Skip to content
BetterDL

Decimal-to-binary conversion

Also called: decimal to binary

Writing a decimal number in binary, either by subtracting the largest powers of 2 that fit or by dividing by 2 repeatedly and reading the remainders.

Converting decimal to binary means finding which powers of 2 add up to your number. There are two standard methods, and they always agree.

Method 1: subtract powers of 2. Walk down the powers 128, 64, 32, 16, 8, 4, 2, 1. If a power fits into what's left, write 1 and subtract it; if not, write 0. It's quick for small numbers and shows exactly why the answer is right.

Largest-first always works because each power is bigger than all the smaller ones combined. If you skip a power that fits, the rest can never make up the gap.

Method 2: repeated division. Divide by 2, write down the remainder, and repeat on the quotient until it reaches 0. The remainders are the bits LSB first, so read them bottom-up. It's purely mechanical and works for any size.

How many bits will you need? The smallest n with 2ⁿ − 1 ≥ your number (see bit width). Check every answer by converting back (binary to decimal conversion).

1
64
0
32
0
16
1
8
1
4
0
2
1
1

Worked examples

Example

77₁₀ by subtracting powers of 2

Largest power first.

  1. 1.

    64 fits: 77 − 64 = 13. Bit 1.

  2. 2.

    32 and 16 don't fit into 13. Bits 0, 0.

  3. 3.

    8 fits: 13 − 8 = 5. Bit 1.

  4. 4.

    4 fits: 5 − 4 = 1. Bit 1.

  5. 5.

    2 doesn't fit: bit 0. 1 fits: bit 1.

  6. 6.

    Result: 1001101₂.

Example

77₁₀ by repeated division

Divide by 2 until the quotient is 0.

  1. 1.

    77 ÷ 2 = 38 r 1, 38 ÷ 2 = 19 r 0, 19 ÷ 2 = 9 r 1, 9 ÷ 2 = 4 r 1.

  2. 2.

    4 ÷ 2 = 2 r 0, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1.

  3. 3.

    Read bottom-up: 1001101₂. Same answer. Check: 64 + 8 + 4 + 1 = 77.

Common mistakes

  • Reading the remainders top-down, which reverses the bits.

  • Writing a 1 for a power that doesn't fit, or skipping one that does.

  • Stopping the division when the quotient is 1 instead of 0, which loses the leading 1.

Practice Decimal-to-binary conversion

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Decimal-to-binary conversion is taught in Number Systems.