Why computers use binary
Computers are built from billions of tiny switches called transistors. Each switch is either off or on, which we write as 0 or 1. A single 0 or 1 is a bit. Eight bits make a byte. Everything a computer stores, from numbers to images to sound, is held as binary.
Try it: the binary converter
Click the bits to switch them on and off. Watch the denary and hexadecimal values change.
Binary to denary
Each column is worth double the one to its right. Add up the columns that have a 1.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 |
01001101 = 64 + 8 + 4 + 1 = 77.
Denary to binary
- Write the column headings 128 to 1.
- Working left to right, put a 1 in any column you can subtract without going below zero, and subtract it.
- Put 0 in the others.
Example: 150 = 128 + 16 + 4 + 2 = 10010110.
Hexadecimal
Hexadecimal (base 16) uses 0 to 9 then A to F for 10 to 15. One hex digit stands for exactly four bits, a nibble, so hex is a shorter, easier way for humans to read binary. It is used for colour codes and memory addresses.
- Split the byte into two nibbles: 1001 0110.
- Convert each nibble: 1001 = 9, 0110 = 6.
- Join them: 96.
To convert hex to denary, multiply the left digit by 16 and add the right digit: 2F = 2 × 16 + 15 = 47.
Binary addition and overflow
| 0 + 0 | 0 |
| 0 + 1 | 1 |
| 1 + 1 | 0, carry 1 |
| 1 + 1 + 1 | 1, carry 1 |
01101100 (108)
+ 00111010 ( 58)
----------
10100110 (166)
If the answer needs more than eight bits, the extra carry has nowhere to go. That is an overflow error, and the stored result is wrong.
Binary shifts
A left shift of one place doubles the number. A right shift of one place halves it, losing any remainder. Bits that fall off the end are lost, which can make the result inaccurate.
Units of data
| 4 bits | 1 nibble |
| 8 bits | 1 byte |
| 1,000 bytes | 1 kilobyte (KB) |
| 1,000 KB | 1 megabyte (MB) |
| 1,000 MB | 1 gigabyte (GB) |
| 1,000 GB | 1 terabyte (TB) |
| 1,000 TB | 1 petabyte (PB) |
GCSE specifications use multiples of 1,000. Check your board's specification.
