How do you convert decimal to binary?
The standard method is repeated division by 2. Divide the number by 2, note the remainder, then divide the quotient again, and stop when the quotient is 0. The remainders, read from bottom to top, are the binary digits. For example, 156 gives remainders 0, 0, 1, 1, 1, 0, 0, 1, which read upward spell 10011100.
Each division strips off the lowest bit: an even number ends in 0, an odd one in 1. That's why the first remainder you write is the rightmost digit of the answer, and why you read the column backwards.
How to use the tool
- Type a non-negative whole number such as
156. - Press Convert.
- Copy the binary result:
10011100.
Digits only. No commas, spaces inside the number, signs, decimal points or scientific notation. Leading and trailing spaces are trimmed, and 0 converts to 0.
Worked example: 156 by repeated division
| Step | Division | Quotient | Remainder |
|---|---|---|---|
| 1 | 156 ÷ 2 | 78 | 0 |
| 2 | 78 ÷ 2 | 39 | 0 |
| 3 | 39 ÷ 2 | 19 | 1 |
| 4 | 19 ÷ 2 | 9 | 1 |
| 5 | 9 ÷ 2 | 4 | 1 |
| 6 | 4 ÷ 2 | 2 | 0 |
| 7 | 2 ÷ 2 | 1 | 0 |
| 8 | 1 ÷ 2 | 0 | 1 |
Reading the remainder column from step 8 up to step 1 gives 10011100. Check it the other way: 128 + 16 + 8 + 4 = 156.
A faster way for small numbers
If you know your powers of two, subtraction is quicker than division. Take the largest power of two that fits, subtract it, and repeat with what's left:
- 156 - 128 = 28, so bit 128 is on
- 28 - 16 = 12, so bit 16 is on
- 12 - 8 = 4, so bit 8 is on
- 4 - 4 = 0, so bit 4 is on
Bits 64, 32, 2 and 1 stay off. Writing 1 for each power used and 0 for each skipped, from 128 down to 1, gives the same 10011100.
Numbers worth recognising
| Decimal | Binary | Why it matters |
|---|---|---|
| 192 | 11000000 | First octet of private 192.168.x.x addresses |
| 255 | 11111111 | Largest value in one byte |
| 1024 | 10000000000 | A power of two is always a 1 followed by zeros |
| 65535 | 1111111111111111 | Largest unsigned 16-bit value, the top TCP/UDP port |
| 4294967295 | 32 ones | Largest unsigned 32-bit value |
Spotting those shapes saves time when you're reading masks, flags and limits in code.
Negative numbers and fractions
This converter handles non-negative integers only, and it's honest about it: -5 and 3.5 both produce an error rather than a guess. Computers store negative integers as two's complement, which depends on the bit width you choose, so there's no single right answer for "-5 in binary" until you say 8, 16 or 32 bits. The FAQ above shows the three-step manual method.
Fractions are a different problem. 0.5 is 0.1 in binary, but 0.1 decimal repeats forever in base 2, which is why floating-point arithmetic has rounding error. To see exactly how a computer stores a fraction, use the IEEE-754 analyzer.
In code
Most languages have this built in. Python's bin() returns '0b10011100' for 156, and JavaScript's toString(2) returns '10011100'. This tool uses the JavaScript method and rejects anything above Number.MAX_SAFE_INTEGER so that very large inputs can't be silently rounded before conversion.
See also
- Binary to decimal reverses the conversion so you can check your work.
- Decimal to hex gives a shorter form of the same value, four bits per digit.
- Text to binary converts characters rather than numbers, one 8-bit byte at a time.
Last updated