Decimal to binary:
the divide-by-2 method and how to check it
Two ways to turn a base-10 number into bits, a quick table of powers of two to check your answer, and what changes for fractions and negatives.
Calcylator Editorial Team
Updated · 5 min read
Why dividing by 2 produces binary digits
Binary writes a number as a sum of powers of two, using only the digits 0 and 1. Each position stands for one power: 1, 2, 4, 8, 16, 32 and so on, doubling as you move left. A 1 means that power is part of the number and a 0 means it is not.
Dividing by 2 peels these powers off from the smallest end. When you halve a whole number, the remainder is either 0 or 1, and that remainder is exactly the digit sitting in the ones place of the binary form. The quotient is what is left once that digit is removed, so you repeat the same step on it.
Continue until the quotient is 0. The first remainder you wrote is the rightmost bit and the last one is the leftmost, which is why the list has to be read backward.
The halving procedure, step by step
- Write the whole number you want to convert.
- Divide it by 2 and note the integer quotient and the remainder (0 or 1).
- Replace the number with the quotient and divide again.
- Stop when the quotient is 0.
- Read the remainders from the last one written to the first.
- n₀:
- the original decimal number
- nₖ₊₁:
- integer quotient after dividing nₖ by 2
- bₖ:
- remainder (0 or 1) and the k-th bit counted from the right
A number n needs ⌊log₂ n⌋ + 1 bits, which is a handy way to know how long the answer should be before you start.
Worked example: 45 in binary
45 ÷ 2
22 remainder 1
22 ÷ 2
11 remainder 0
11 ÷ 2
5 remainder 1
5 ÷ 2
2 remainder 1
2 ÷ 2
1 remainder 0
1 ÷ 2
0 remainder 1
Remainders read bottom to top
101101 (base 2)
Check: 32 + 8 + 4 + 1 = 45.
Six divisions gave six bits, matching ⌊log₂ 45⌋ + 1 = 5 + 1 = 6. By luck, 45 is a palindrome in binary, so reading in the wrong direction would give the same string. Always read from the final remainder upward anyway: 13 produces remainders 1, 0, 1, 1 in that order, and the correct answer is 1101, not 1011.
A few conversions to practise on
Working through a handful of values builds the pattern faster than rereading the method. Cover the right-hand column, convert the number yourself, then compare.
| Decimal | Binary | Place values that add up |
|---|---|---|
| 7 | 111 | 4 + 2 + 1 |
| 10 | 1010 | 8 + 2 |
| 25 | 11001 | 16 + 8 + 1 |
| 64 | 1000000 | 64 |
| 200 | 11001000 | 128 + 64 + 8 |
| 255 | 11111111 | every place from 128 down to 1 |
Notice the shapes. Every power of two is a single 1 followed by zeros, and every number one below a power of two is a run of ones. That is why 255 is all ones in a byte and 64 is a lone 1 in the seventh place.
The subtraction method with powers of two
Some people prefer to work from the left. List the powers of two up to your number, then for each one from the largest downward write 1 if it fits in what remains and subtract it, otherwise write 0.
| Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Bit for 45 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 |
For 100: 64 fits (36 left), 32 fits (4 left), 16 and 8 do not, 4 fits (0 left). The bits are 1100100. This route is faster for small numbers, while repeated halving is easier to run mechanically for large ones.
Fractions and negative numbers
The halving method handles whole numbers only. For the fractional part, multiply by 2 repeatedly and take the integer part each time: 0.625 × 2 = 1.25 gives 1, 0.25 × 2 = 0.5 gives 0, 0.5 × 2 = 1.0 gives 1, so 0.625 is 0.101 in binary.
Many decimal fractions never finish. 0.1 becomes 0.0001100110011… and repeats forever, which is the reason computers store 0.1 + 0.2 as a value that is very slightly off.
Negative integers are normally stored in two's complement. Take 45 as 8 bits (00101101), flip every bit (11010010) and add 1 to get 11010011, the 8-bit pattern for −45. The sign is carried by the leftmost bit, so the width you choose matters.
A quick way to see the width limit: in 8 bits the largest positive two's-complement value is 01111111, which is 127, and the pattern 10000000 stands for −128. Convert 200 into 8 bits and you will get 11001000, which the same machine would read as −56 if it were treating the byte as signed. The bits are identical; only the interpretation changes.
Where conversions go wrong
- Reading the remainders top to bottom instead of bottom to top.
- Stopping when the quotient is 1 and forgetting the final 1 as the leading bit.
- Dropping leading zeros when a fixed width such as 8 bits is required: 13 is 1101, but as a byte it is 00001101.
- Mixing up place values by starting the powers at 2 instead of 2⁰ = 1.
Practical uses include reading subnet masks, setting permission flags and understanding why a byte tops out at 255 (11111111, which is 2⁸ − 1).
Where you meet binary in real work
A computer stores a whole number in a fixed number of bits, and the choice of width sets the largest value it can hold. Eight bits give 256 combinations, from 0 to 255. Sixteen bits reach 65,535, and thirty-two bits go past four billion.
Network addresses are the most common place a developer converts by hand. Each part of an IPv4 address is one byte. The number 192 is 11000000 and 168 is 10101000, so 192.168 begins with those two bytes. A subnet mask of 255.255.255.0 is twenty-four ones followed by eight zeros, which is the same thing written as /24.
Hexadecimal is a shorthand for the same bits. Split the binary into groups of four from the right and write each group as one hex digit. For 45, 0010 1101 becomes 2D, since 2 × 16 + 13 = 45. Programmers move between the three notations constantly, and the divide-by-2 method is the foundation under all of them.
Common questions
How do you convert decimal to binary by hand?
Divide the number by 2 repeatedly, writing down each remainder, until the quotient reaches 0. Then read the remainders from the last one to the first. For 45 the remainders give 101101, and 32 + 8 + 4 + 1 confirms it equals 45.
What is 100 in binary?
100 in decimal is 1100100 in binary, because 64 + 32 + 4 = 100. As an 8-bit value, pad it with one leading zero to get 01100100. The same answer comes from halving 100 until you reach zero and reading the remainders upward.
How many bits do I need for a decimal number?
Use ⌊log₂ n⌋ + 1 for a positive whole number n. For 45 that is 6 bits, and for 255 it is 8 bits. A fixed width of 8 bits can hold 0 to 255, or −128 to 127 in two's complement.
Why do you read the remainders backward?
The first remainder you get is the ones place, the least significant bit, which belongs at the far right. Each later remainder belongs one place further left, so the last remainder written is the leading bit and must be written first in the answer.
Was this guide helpful?
Continue reading
View all blogsHow Big Will a Video File Be? Bitrate Math
A video file is bitrate × duration ÷ 8. At 8 Mbps video plus 128 kbps audio, ten minutes is about 610 MB. Here is the math and the traps.
5 min read
Megapixels: Image Size and Print Resolution
Megapixels are width × height ÷ 1,000,000. A 6000 × 4000 photo is 24 MP and prints about 20 × 13.3 inches at 300 PPI. See how to size for print.
5 min read
Requests Per Second and API Throughput
RPS is requests ÷ seconds, and concurrency is RPS × latency. 1.8 million hits an hour is 500 RPS, about 20 requests in flight at 40 ms.
5 min read




