What is binary?
Binary is the base 2 number system. Instead of ten digits it uses just two, 0 and 1, and each place is worth twice the place to its right: 1, 2, 4, 8, 16, 32 and so on. Computers store everything as binary because an electrical switch has two natural states, off and on. A single binary digit is a bit, and eight bits make a byte.
Binary to decimal
Multiply each digit by its place value and add the results. For 10111 the places from the left are 16, 8, 4, 2 and 1:
Decimal to binary
Divide the number by 2 repeatedly and record each remainder. The remainders read from last to first form the binary number. For 18: 18 ÷ 2 = 9 r 0, 9 ÷ 2 = 4 r 1, 4 ÷ 2 = 2 r 0, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1. Reading upward gives 10010. Another way to see it is 18 = 16 + 2, so the bits for 16 and 2 are on.
| Decimal | Binary | Decimal | Binary |
|---|---|---|---|
| 0 | 0 | 8 | 1000 |
| 1 | 1 | 9 | 1001 |
| 2 | 10 | 10 | 1010 |
| 3 | 11 | 12 | 1100 |
| 4 | 100 | 15 | 1111 |
| 5 | 101 | 16 | 10000 |
| 7 | 111 | 20 | 10100 |
Binary addition
Add column by column from the right using four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1). Example: 101 + 11. The rightmost column is 1 + 1 = 10, so write 0 and carry 1. The next is 0 + 1 + 1 = 10, write 0 and carry 1. The last is 1 + 1 = 10, giving 1000. In decimal that is 5 + 3 = 8.
Binary subtraction
Subtract column by column, borrowing from the next column to the left when you need to take 1 from 0. Borrowing turns the 0 into 10 (two) and reduces the neighbor by one. For 1010 − 11, borrow to get 111 in the end, which is 10 − 3 = 7. If the second number is larger the answer is negative, and the calculator shows it with a minus sign.
Binary multiplication
Multiplying works like long multiplication in decimal, but each partial product is either zero or a shifted copy of the top number. For 10111 × 11, write 10111 once for the ones bit, and 10111 shifted one place left for the twos bit, then add: 10111 + 101110 = 1000101. In decimal, 23 × 3 = 69, which is 1000101 in binary.
Binary division
Long division uses the same steps as decimal, only each quotient digit is 0 or 1. For 10101 ÷ 11, the quotient is 111 with remainder 0, because 21 ÷ 3 = 7. When a division is not exact, this calculator reports the whole-number quotient and the remainder, so that divisor × quotient + remainder equals the dividend.
Where binary is used
- Computer memory, processors and file sizes.
- IP addresses and subnet masks, which are 32 bits long in IPv4.
- Bitwise flags and permissions in software.
- Digital logic and electronics.
Tips for working in binary
Learn the powers of two up to 1,024, because they appear constantly: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1,024. Group long binary strings in fours from the right to read them more easily, since each group of four bits is one hex digit. A number ending in 0 is even and one ending in 1 is odd. Shifting left by one place doubles a value, and shifting right halves it, ignoring the remainder. These shortcuts make mental checks fast: 1000101 has bits for 64, 4 and 1, which is 69.