To convert between binary and denary, use place values: in an 8-bit number the columns from left to right are worth 128, 64, 32, 16, 8, 4, 2 and 1. Binary to denary means adding the columns that hold a 1. Denary to binary means deciding, column by column, whether that place value fits.
This skill opens Representing numbers and text and returns in hexadecimal, binary addition and bit depth.
How do place values work in binary?
In denary, the number 345 means 3 hundreds, 4 tens and 5 ones. Each column is 10 times the one on its right. In binary each column is 2 times the one on its right, so the columns are 1, 2, 4, 8, 16, 32, 64, 128 reading from the right.
| Column value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Bit | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
Add the values above each 1: 128 + 32 + 16 + 4 + 1 = 181. So 10110101 in binary is 181 in denary.
How do you convert denary to binary?
Work from the biggest column to the smallest. At each column ask: does this value fit into what is left?
- Write the eight column values above eight empty boxes.
- If the place value is less than or equal to the number left, write 1 and subtract it.
- If not, write 0 and leave the number unchanged.
- Continue until the last column. The number left should now be 0, which is your check.
Worked example
Convert 183 to 8-bit binary.
| Column | Number left before | Fits? | Bit | Number left after |
|---|---|---|---|---|
| 128 | 183 | yes | 1 | 55 |
| 64 | 55 | no | 0 | 55 |
| 32 | 55 | yes | 1 | 23 |
| 16 | 23 | yes | 1 | 7 |
| 8 | 7 | no | 0 | 7 |
| 4 | 7 | yes | 1 | 3 |
| 2 | 3 | yes | 1 | 1 |
| 1 | 1 | yes | 1 | 0 |
The answer is 10110111. Check by adding back: 128 + 32 + 16 + 4 + 2 + 1 = 183. It matches, and the number left ended at 0.
How can the same method be written as an algorithm?
The table above is exactly what this pseudocode does.
DECLARE Number : INTEGER
DECLARE Place : INTEGER
DECLARE Bits : STRING
Number ← 183
Place ← 128
Bits ← ""
WHILE Place >= 1
IF Number >= Place
THEN
Bits ← Bits & "1"
Number ← Number - Place
ELSE
Bits ← Bits & "0"
ENDIF
Place ← Place DIV 2
ENDWHILE
OUTPUT Bits
Trace it:
| Place | Number >= Place? | Bits | Number |
|---|---|---|---|
| 128 | yes | “1” | 55 |
| 64 | no | “10” | 55 |
| 32 | yes | “101” | 23 |
| 16 | yes | “1011” | 7 |
| 8 | no | “10110” | 7 |
| 4 | yes | “101101” | 3 |
| 2 | yes | “1011011” | 1 |
| 1 | yes | “10110111” | 0 |
After Place = 1, Place becomes 0 and the loop stops. The output is 10110111. You can confirm in the Python reasoning sandbox with print(format(183, "08b")) and print(int("10110111", 2)).
The mistake to watch for
A common slip is reading the place values from the wrong end, so the left-most bit is treated as worth 1.
Question: Convert 110100 to denary.
Mistaken working: 1×1 + 1×2 + 0×4 + 1×8 + 0×16 + 0×32 = 11
The columns for a 6-bit number are 32, 16, 8, 4, 2, 1 from the left. The correct working is 32 + 16 + 4 = 52. To avoid the slip, write the column values above the bits before you add anything, always starting from 1 on the right and doubling as you move left.
Check yourself
1. Convert 00110110 to denary.
Show answer
Columns with a 1: 32, 16, 4, 2. Sum: 32 + 16 + 4 + 2 = 54.
2. Convert 200 to 8-bit binary.
Show answer
128 fits (72 left). 64 fits (8 left). 32 no, 16 no. 8 fits (0 left). 4, 2, 1 no. Bits: 1 1 0 0 1 0 0 0, so 11001000. Check: 128 + 64 + 8 = 200.
3. Why can an 8-bit register not store the denary number 256?
Show answer
The largest 8-bit value is 11111111 = 255. The number 256 needs a ninth column worth 256, so it needs 9 bits.
Where this leads next
Once conversions are quick, learn to use hexadecimal as a compact way to write binary, then try the mixed practice set. The Python reasoning sandbox and the pseudocode trace trainer let you test your own examples.
Some students can convert slowly and correctly but run out of time in a paper. That is a pattern our teachers can work on in online one-to-one Computer Science tuition.