Developer Bases

Decimal to binary

Decimal value
Binary 10101010
Divide by two, keep the remainders
The same number elsewhere
Decimal 170
Binary, grouped 1010 1010
Octal 252
Hexadecimal AA
Bits needed 8
Note
Grouped into nibbles · four bits per hex digit
DecimalBinaryOctalHex
0000
1111
81000108
10101012A
15111117F
16100002010
64100000010040
100110010014464
25511111111377FF
256100000000400100
1024100000000002000400
655351111111111111111177777FFFF
Advertisement
320 × 100

Divide repeatedly by two and read the remainders backwards. 170 gives 10101010. Alternatively subtract the largest power of two that fits and repeat: 170 − 128 − 32 − 8 − 2 = 0.

How to convert decimal to binary

1 Enter the decimal number.
2 Read the binary, both run together and grouped into nibbles of four.
3 Check the bits row when you are picking a field width.
4 Use the grouped form when writing it down: it is far easier to check.

The subtraction method is faster by hand than repeated division. Write down the powers of two above your number, then work down: does 128 fit in 200? Yes, so write 1 and subtract, leaving 72. Does 64 fit in 72? Yes, leaving 8. Does 32 fit in 8? No, write 0 — and so on down to 11001000. It produces the digits left to right in one pass rather than in reverse.

A few shapes are worth recognising rather than converting. Every power of two is a single 1 followed by zeros, so 1024 is a 1 and ten zeros. Every number one below a power of two is a solid run of ones, so 255 is eight of them. And the last digit alone tells you odd or even, because it is the only place worth 1.

The decimal point is refused rather than truncated, and that is deliberate. Binary fractions exist. The places after the point are halves, quarters, eighths, but most decimal fractions have no exact binary form. 0.1 repeats forever in binary, which is the whole reason 0.1 + 0.2 does not give exactly 0.3 in floating-point arithmetic. Silently dropping the fraction would hand back an answer that looks right and is not.

Questions

1010.

Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding