2.1 Binary numbers: convertingCounting in base 2

Our everyday numbers are base 10, also called decimal. There are ten digits, 0 to 9, and each place is worth ten times the place to its right: ones, tens, hundreds, thousands. The number 4,072 means 4 thousands, 0 hundreds, 7 tens and 2 ones.
| Place (base 10) | Thousands | Hundreds | Tens | Ones |
|---|---|---|---|---|
| Digit in 4,072 | 4 | 0 | 7 | 2 |
| Worth | 4 × 1,000 | 0 × 100 | 7 × 10 | 2 × 1 |
?Wait, what's an exponent again?
Binary is base 2. There are only two digits, 0 and 1, and each place is worth twice the place to its right: 1, 2, 4, 8, 16, 32, 64, 128, and so on. The rightmost bit is the ones place. To read a binary number, write the place values over the bits and add up the places that hold a 1.
| place value | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|
| bit | 1 | 0 | 1 | 1 | 0 |
| adds | 16 | 0 | 4 | 2 | 0 |
Going the other way, from decimal to binary, use the "biggest power that fits" method. List the powers of 2 up to your number. Starting from the biggest, ask: does it fit in what's left? If yes, write a 1 and subtract it. If no, write a 0. Keep going down to the ones place.
| power | fits in what is left? | bit | left over |
|---|---|---|---|
| 64 | 64 ≤ 77: yes | 1 | 13 |
| 32 | 32 ≤ 13: no | 0 | 13 |
| 16 | 16 ≤ 13: no | 0 | 13 |
| 8 | 8 ≤ 13: yes | 1 | 5 |
| 4 | 4 ≤ 5: yes | 1 | 1 |
| 2 | 2 ≤ 1: no | 0 | 1 |
| 1 | 1 ≤ 1: yes | 1 | 0 |
?Wait, what does MOD do?
A computer would use a different method, and it's worth seeing because it's a tiny algorithm you can trace. Divide by 2 again and again. Each remainder is the next bit, working from the right. Here it is in the exam's pseudocode. INSERT(bits, 1, x) puts x at the front of the list, so the bits come out in the right order.
1n ← 222bits ← []3REPEAT UNTIL (n = 0)4{5 INSERT(bits, 1, n MOD 2)16 n ← (n - n MOD 2) / 227}8DISPLAY(bits)
- line 5 The remainder is the next bit, added at the front
- line 6 Drop that bit and halve: 22 becomes 11
| n | n MOD 2 | bits after INSERT | new n |
|---|---|---|---|
| 22 | 0 | [0] | 11 |
| 11 | 1 | [1, 0] | 5 |
| 5 | 1 | [1, 1, 0] | 2 |
| 2 | 0 | [0, 1, 1, 0] | 1 |
| 1 | 1 | [1, 0, 1, 1, 0] | 0 |
I thought about it. Show me
- Convert 110010. Places from the left: 32, 16, 8, 4, 2, 1. The 1s are in 32, 16 and 2: 32 + 16 + 2 = 50.
Why?
A six-bit number has places up to 32. Always label the places before adding. - Convert 101111. The 1s are in 32, 8, 4, 2 and 1: 32 + 8 + 4 + 2 + 1 = 47.
- Now all three are in base 10: 50, 49 and 47. In order: 47, 49, 50.
Why?
You can't compare numbers written in different bases by looking at them. Convert to one base first.
Answer: Binary 101111 (47), then decimal 49, then binary 110010 (50).
Stuck? Get a hint
- Write 32, 16, 8, 4, 2, 1 over each six-bit number.
- Add only the places under a 1.
- Once all three are decimal, ordering is easy.
- Powers of 2 up to 200: 128, 64, 32, 16, 8, 4, 2, 1. (256 is too big.)
- 128 fits: bit 1, 72 left. 64 fits in 72: bit 1, 8 left. 32 and 16 don't fit in 8: bits 0, 0.
Why?
At each place ask: is this power at most what is left? - 8 fits exactly: bit 1, 0 left. 4, 2 and 1: bits 0, 0, 0.
- Read the bits in order: 11001000. Check: 128 + 64 + 8 = 200.
Why?
Converting back is a quick way to catch a slip.
Answer: 200 = 11001000.
Stuck? Get a hint
- Start with the biggest power of 2 that is at most 200.
- 200 - 128 = 72, and 72 - 64 = 8.
- 8 is itself a power of 2.
- A91
- B109
- C117
- D182
Show the answer
B. Places from the left for seven bits: 64, 32, 16, 8, 4, 2, 1. The 1s are in 64, 32, 8, 4 and 1: 64 + 32 + 8 + 4 + 1 = 109. 182 is the trap: it treats the leftmost bit as 128, as if there were eight bits.
- A100111
- B110011
- C100101
- D101001
Show the answer
A. 39 = 32 + 4 + 2 + 1, so the places 32, 16, 8, 4, 2, 1 get 1, 0, 0, 1, 1, 1. The others are 51, 37 and 41.
Beyond the course, as a bonus: programmers often write long binary patterns in base 16, hexadecimal, where each digit stands for four bits. The AP exam sticks to binary and decimal.

On a "which is largest" question that mixes bases, convert everything to decimal before you compare. A long binary number like 10000 is only 16, and decimal 15 is close behind.
- Binary is base 2. Places from the right: 1, 2, 4, 8, 16, 32, 64, 128.
- Binary to decimal: add the place values under each 1.
- Decimal to binary: take out the biggest power of 2 that fits, and repeat.
- A binary number is odd exactly when its rightmost bit is 1. Compare across bases only after converting.