Decimal to binary converter
A decimal to binary calculator that shows its work: type a decimal number to get it in binary, with the division steps.
Prefixes 0b, 0o, 0x and spaces or underscores between digits are fine. A point starts the fraction.
How to convert decimal to binary
Divide the number by 2 and write down the remainder, 0 or 1. Divide the quotient by 2 again, and keep going until the quotient is 0. The remainders, read from the last one to the first, are the binary digits.
| Divide | 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 remainders from the bottom up gives 10011100, so 15610 = 100111002.
Negative numbers
Computers store negative whole numbers in two’s complement. To write −18 in 8 bits: write 18 in binary (00010010), flip every bit (11101101), then add 1 (11101110). Tick “Read as signed” in the converter and pick a width to get this directly.
Powers of 2
| Power | Decimal | Binary |
|---|---|---|
| 20 | 1 | 1 |
| 21 | 2 | 10 |
| 22 | 4 | 100 |
| 23 | 8 | 1000 |
| 24 | 16 | 1 0000 |
| 25 | 32 | 10 0000 |
| 26 | 64 | 100 0000 |
| 27 | 128 | 1000 0000 |
| 28 | 256 | 1 0000 0000 |
| 29 | 512 | 10 0000 0000 |
| 210 | 1,024 | 100 0000 0000 |
| 211 | 2,048 | 1000 0000 0000 |
| 212 | 4,096 | 1 0000 0000 0000 |
| 213 | 8,192 | 10 0000 0000 0000 |
| 214 | 16,384 | 100 0000 0000 0000 |
| 215 | 32,768 | 1000 0000 0000 0000 |
| 216 | 65,536 | 1 0000 0000 0000 0000 |
How it’s calculated
Conversions use exact whole-number arithmetic (JavaScript BigInt), so long numbers keep every digit. Fractions are kept as exact ratios; when the digits repeat, the repeating block is found and marked instead of rounded.
Questions
How do I convert a decimal fraction to binary?
Multiply the fraction by 2. The whole-number part (0 or 1) is the next bit; keep the fraction part and repeat. 0.625 gives 1, 0, 1, so it is 0.101. Some fractions, like 0.1, never end in binary; the converter marks the repeating block.
How many bits do I need for a number?
A number below 2n fits in n bits. 255 fits in 8 bits, 65,535 in 16, and 4,294,967,295 in 32.
Why does 0.1 not convert exactly?
0.1 is 1/10, and 10 has a factor of 5, which binary can’t represent with a finite number of bits. The bits 0011 repeat forever.