Why computers use binary
Computers are built from billions of switches that can only be on (1) or off (0), so every piece of data - numbers, text, images, sound - has to be stored and processed as binary. A single binary digit is called a bit.
Bits, nibbles, bytes and beyond
- A bit is one 0 or 1.
- A nibble is 4 bits.
- A byte is 8 bits.
- With n bits you can make 2^n different values, so a byte (8 bits) gives 2^8 = 256 possible values, numbered 0 to 255.
- Edexcel uses the 1000-based prefixes: 1 kilobyte (KB) = 1000 bytes, 1 megabyte (MB) = 1000 KB, 1 gigabyte (GB) = 1000 MB, 1 terabyte (TB) = 1000 GB.
Converting binary and denary
Each column in an 8-bit binary number is worth (from left to right) 128, 64, 32, 16, 8, 4, 2, 1. To convert binary to denary, add up the column values where there is a 1. To convert denary to binary, subtract the biggest column value you can, put a 1 there, and repeat with the remainder. To convert denary to hexadecimal, first convert to binary, split into two nibbles (groups of 4 bits), then convert each nibble to a single hex digit (0-9, then A-F for 10-15).
Hexadecimal
Hex is used as shorthand for binary because two hex digits neatly represent one byte, and it is easier for humans to read and type than long strings of 1s and 0s. Common uses include MAC addresses and colour codes (like #FF0000 for red).
Binary addition and overflow
When adding two binary numbers, add column by column and carry into the next column when a total reaches 2, just like carrying in denary addition. If an 8-bit register cannot hold the result of an addition, this is called overflow, and it can cause errors because the extra bit is lost.
Binary shifts
A left shift multiplies a binary number by 2 for every place shifted; a right shift divides by 2 for every place shifted (dropping remainders). Shifting is a fast way for computers to do multiplication and division by powers of two.
Common mistakes
- Mixing up KB (1000 bytes) with the older KiB (1024 bytes) - Edexcel exams use 1000.
- Forgetting to pad binary numbers to 8 bits with leading zeros.
- Muddling up which way column values go (128 is leftmost, not rightmost).
- Losing carried bits when adding binary numbers.
How many bits are in a byte?
8 bits
tap to reveal
How many bits are in a nibble?
4 bits
tap to reveal
How many different values can 8 bits represent?
256 (2^8), numbered 0 to 255
tap to reveal
What formula gives the number of values n bits can represent?
2^n
tap to reveal
In Edexcel GCSE CS, how many bytes are in 1 kilobyte?
1000 bytes
tap to reveal
What are the column values of an 8-bit binary number, left to right?
128, 64, 32, 16, 8, 4, 2, 1
tap to reveal
Convert binary 00101101 to denary
45 (32+8+4+1)
tap to reveal
How many hex digits are needed to represent one byte?
Two hex digits
tap to reveal
What denary value does hex digit F represent?
15
tap to reveal
What does a left shift of 2 places do to a binary value?
Multiplies it by 4 (2^2)
tap to reveal
What does a right shift do to a binary value?
Divides it by 2 for each place shifted, dropping any remainder
tap to reveal
What is overflow in binary addition?
When a result needs more bits than are available, so the extra bit is lost and the answer is wrong
tap to reveal
Why is hexadecimal used instead of binary in things like MAC addresses and colour codes?
It is far more compact and easier for humans to read and write than long binary strings
tap to reveal
What is the first step to convert a denary number to hexadecimal?
Convert the denary number to binary first, then split into nibbles and convert each to a hex digit
tap to reveal
When adding binary, when do you carry to the next column?
Whenever the total in a column reaches 2
tap to reveal