AQA GCSE Computer Science (8525), section 3.3.2 (Converting between number bases)
Place values
In binary, each column is worth double the one to its right. With 8 bits (one byte):
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|
The largest 8-bit number is 1111 1111 = 255, and the smallest is 0. So 8 bits can store 256 different values (0 to 255).
With bits there are different values.
Binary to decimal
Write the binary number under the place values and add up the values with a 1.
1001 1100
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
.
Decimal to binary
Work from the left. For each place value: if it fits in the number left, write 1 and subtract it; otherwise write 0.
Convert 156:
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Fits in what is left? | 156: yes | 28: no | 28: no | 28: yes | 12: yes | 4: yes | 0: no | 0: no |
| Bit | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
So .
Another example
Convert 77: , so 0100 1101.
Tips
- An odd number always ends in 1; an even number ends in 0.
- Write leading zeros so that you give a full 8 bits when the question asks for 8 bits.
- Check by converting your answer back.
Common mistake: forgetting the leading zeros (writing 1101 instead of 0000 1101 when 8 bits are asked for), or writing the place values in the wrong order. The largest place value (128) is on the left.
Exam tip: always write out the place value headings 128 to 1 above your answer. Check your answer by adding up the values of the columns that contain a 1.
Check yourself
Convert 0011 0101 to decimal.
32 + 16 + 4 + 1 = 53.
Convert 200 to 8-bit binary.
1100 1000.