Unit 1: Digital information · Binary numbers

Article

Converting decimal numbers to binary

7 min read

To turn the number 45 into binary, ask one question: which binary place values add up to 45? There are two reliable ways to find out. Pick the one you like best, and use the other to check your work.

Method 1: take the biggest place you can

Write the binary place values: 128, 64, 32, 16, 8, 4, 2, 1. Start at the left. For each place:

  • If the place value is less than or equal to what is left, write 1 and subtract the place value.
  • If not, write 0 and keep what is left.

When you reach the 1s place, nothing should be left. Here it is for 45:

Place valueDoes it fit in what is left?BitLeft after
128No (128 is more than 45)045
64No045
32Yes113
16No (16 is more than 13)013
8Yes15
4Yes11
2No01
1Yes10

Read the Bit column from top to bottom: 00101101. The two zeros at the start are leading zeros. They do not change the value, so you can write the answer as 101101.

Check it by adding the places that have a 1: 32 + 8 + 4 + 1 = 45. Good.

Method 1 for each place

  1. Take the biggest place

    for example 128

    compare
  2. Does it fit in what is left?

    yes: write 1 and subtract it. No: write 0

    next place down
  3. Stop after the 1s place

    nothing should be left

Repeat the middle step for every place, from the biggest down to the 1s place.

Check your understanding

Which binary number is equal to the decimal number 20?

Method 2: halve again and again

Divide the number by 2. Write down the remainder, which is the amount left over (it is always 0 or 1). Then divide the answer by 2 again. Keep going until the answer is 0. Here it is for 13:

13 ÷ 2 = 6   remainder 1
 6 ÷ 2 = 3   remainder 0
 3 ÷ 2 = 1   remainder 1
 1 ÷ 2 = 0   remainder 1

Now read the remainders from the bottom up: 1101. Check: 8 + 4 + 1 = 13.

Method 2 in four moves

  1. Divide by 2

    write the remainder
  2. Remainder is 0 or 1

    divide the answer again
  3. Stop when the answer is 0

  4. Read the remainders bottom up

    13 gives 1101

The first remainder is the 1s place, so it ends up on the right.

Why does this work? The first remainder tells you whether the number is odd, and that is exactly what the 1s place stores. Dividing by 2 then drops the 1s place and moves every other place one step to the right. So the next remainder is the old 2s place, then the old 4s place, and so on.

Check your understanding

Which binary number is equal to the decimal number 37?

Worked example: 77 by Method 1

The place values 128, 64, 32, 16, 8, 4, 2, 1 give:

  • 128 does not fit in 77, so write 0.
  • 64 fits. Write 1. Left: 77 − 64 = 13.
  • 32 and 16 do not fit in 13. Write 0 and 0.
  • 8 fits. Write 1. Left: 5.
  • 4 fits. Write 1. Left: 1.
  • 2 does not fit. Write 0.
  • 1 fits. Write 1. Left: 0.

The bits are 01001101, which is 1001101 without the leading zero. Check: 64 + 8 + 4 + 1 = 77.

Common mistakes

  • Reading the remainders from the top down in Method 2. You must read them from the bottom up, or the number comes out backwards.
  • Skipping a place. Every place needs a bit, even when it is 0. Missing a 0 shifts all the other digits.
  • Starting with the smallest place in Method 1. Start with the biggest place that fits.
  • Not checking. Add the places with a 1 at the end. If you do not get the number you started with, find the mistake.

On the exam

You will be given a small decimal number, often below 100, and asked for its binary form. Many learners find Method 1 faster. Always add up your answer as a final check.

Key words

Convert: change a number from one number system to another.

Remainder: what is left over after a division.

Leading zero: a 0 at the left end of a number. It does not change the value.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this site. All lessons and questions here are written by JrCodex.