Decimal to Binary: The Divide by 2 Method, Step by Step
Convert decimal to binary by dividing by 2 and reading the remainders from bottom to top. Includes a powers of two chart, worked examples and negative numbers.
Updated
To convert decimal to binary, divide the number by 2 repeatedly, writing down each remainder, until the quotient is 0. The binary number is the remainders read from bottom to top. For example, 13 gives remainders 1, 0, 1, 1, which read in reverse order make 1101.
The divide by 2 method
- Divide the decimal number by 2.
- Write down the remainder. It will always be 0 or 1.
- Replace the number with the quotient and repeat.
- Stop when the quotient reaches 0.
- Read the remainders from the last one you wrote to the first.
Worked example: convert 156.
| Division | Quotient | Remainder |
|---|---|---|
| 156 / 2 | 78 | 0 |
| 78 / 2 | 39 | 0 |
| 39 / 2 | 19 | 1 |
| 19 / 2 | 9 | 1 |
| 9 / 2 | 4 | 1 |
| 4 / 2 | 2 | 0 |
| 2 / 2 | 1 | 0 |
| 1 / 2 | 0 | 1 |
Reading the remainder column from bottom to top gives 10011100. So 156 in decimal is 10011100 in binary.
Why it works
Each division by 2 asks one question: is the number odd or even? The remainder is the answer, and it is exactly the rightmost binary digit, the ones place. Dividing then throws that digit away and shifts everything one place to the right, so the next remainder is the twos place, then the fours place, and so on. You discover the bits from right to left, which is why you read them in reverse at the end.
The subtraction method
If you know your powers of two, there is a second method that builds the answer from left to right.
- Find the largest power of two that fits into the number. Write a 1.
- Subtract it.
- Move to the next smaller power of two. If it fits into what is left, write 1 and subtract it. If not, write 0.
- Continue down to 1.
For 156: 128 fits, leaving 28 (write 1). 64 does not fit (0). 32 does not fit (0). 16 fits, leaving 12 (1). 8 fits, leaving 4 (1). 4 fits, leaving 0 (1). 2 does not fit (0). 1 does not fit (0). The result is 10011100, the same as before.
This method is quicker for mental arithmetic with small numbers. The divide by 2 method is better for large numbers, because you never need a power of two bigger than 2.
Powers of two chart
| Power | Value | Power | Value |
|---|---|---|---|
| 2^0 | 1 | 2^9 | 512 |
| 2^1 | 2 | 2^10 | 1,024 |
| 2^2 | 4 | 2^11 | 2,048 |
| 2^3 | 8 | 2^12 | 4,096 |
| 2^4 | 16 | 2^13 | 8,192 |
| 2^5 | 32 | 2^14 | 16,384 |
| 2^6 | 64 | 2^15 | 32,768 |
| 2^7 | 128 | 2^16 | 65,536 |
| 2^8 | 256 | 2^32 | 4,294,967,296 |
The chart also tells you how many bits a number needs. A number smaller than 2^n fits in n bits. Since 156 is smaller than 256, it fits in 8 bits.
Common decimal to binary values
| Decimal | Binary | Decimal | Binary |
|---|---|---|---|
| 1 | 1 | 16 | 10000 |
| 2 | 10 | 32 | 100000 |
| 3 | 11 | 50 | 110010 |
| 4 | 100 | 64 | 1000000 |
| 5 | 101 | 100 | 1100100 |
| 7 | 111 | 127 | 1111111 |
| 8 | 1000 | 128 | 10000000 |
| 10 | 1010 | 255 | 11111111 |
| 12 | 1100 | 256 | 100000000 |
| 15 | 1111 | 1,000 | 1111101000 |
Padding to a fixed width
Computers store numbers in fixed sizes, usually 8, 16, 32 or 64 bits. To fit a result to a width, add zeros on the left. Decimal 13 is 1101, and as one byte it is 00001101. Leading zeros never change the value, just as 0042 is still 42.
Negative numbers, briefly
A minus sign is not available inside a computer, so negative whole numbers are stored using two's complement. To write a negative number at a given width:
- Write the positive value in binary, padded to the full width.
- Flip every bit: each 0 becomes 1 and each 1 becomes 0.
- Add 1.
For -42 in 8 bits: 42 is 00101010. Flipped, that is 11010101. Adding 1 gives 11010110.
The width matters. The same -42 in 16 bits is 1111111111010110. An 8-bit two's complement number covers -128 to 127, and a 32-bit one covers -2,147,483,648 to 2,147,483,647. Reading these bit patterns back is covered in Binary to Decimal.
Decimal fractions
For the part after the decimal point, multiply by 2 instead of dividing. The whole number part of each result (0 or 1) is the next bit, and you carry on with the fraction that remains.
For 0.625: doubling gives 1.25, so the first bit is 1 and 0.25 remains. Doubling gives 0.5, so the next bit is 0. Doubling gives 1.0, so the last bit is 1 and nothing remains. The answer is 0.101.
Not every fraction ends. Decimal 0.1 becomes 0.000110011... with 0011 repeating forever. That is why 0.1 + 0.2 does not come out as exactly 0.3 in most programming languages.
Using the converter
In the Number Base Converter, type a number into the decimal field and the binary field fills in immediately, grouped in fours for readability, together with the octal and hexadecimal forms. A panel underneath shows the value padded to 8, 16 and 32 bits, which saves the padding step.
The decimal field accepts a leading minus sign. Negative numbers are shown as 32-bit two's complement, so -42 appears as 32 bits ending in 1101 0110, and the 8-bit row shows 11010110, matching the hand calculation above. The converter handles whole numbers within the 32-bit range and does not take fractions, so use the multiply by 2 method for those.
Long binary strings are easier to handle in base 16, where each group of four bits becomes one digit. What Is Hexadecimal explains how.
Try it
Enter 156 in the decimal field of the Number Base Converter and confirm the binary reads 1001 1100. Then try -42 and compare the 8-bit row against the flip and add 1 steps. The other number tools are in the numbers category.