Why binary?
A computer is made from billions of tiny switches called transistors. Each switch has two states: on or off. That is it. There is no "a bit on" or "mostly off". Just two states.
Because there are only two states, computers use a number system with only two digits: 0 and 1. A 0 represents a switch that is off. A 1 represents a switch that is on. This is binary.
Every piece of data a computer handles, whether it is a number, a letter, an image, a sound file or a video, is ultimately stored as a sequence of 0s and 1s. Understanding how that works is fundamental to everything else in this course.
Denary (base 10)
The number system you use every day is denary, also called base 10. It uses ten digits: 0 through 9. The position of each digit tells you its value.
Take the number 347. It means:
3 × 100 + 4 × 10 + 7 × 1 = 347. Each column is ten times the value of the column to its right. That is what "base 10" means.
Binary (base 2)
Binary works exactly the same way, but each column is two times the value of the column to its right, and the only digits available are 0 and 1.
Here is an 8-bit binary number: 10110101
To convert to denary, add up the column values where there is a 1:
128 + 32 + 16 + 4 + 1 = 181
Converting denary to binary
The most reliable method is repeated division by 2. Divide your number by 2, note the remainder, repeat until you reach 0. Read the remainders from bottom to top.
Check: 64 + 16 + 8 + 4 + 1 = 93. Correct.
Binary addition
Adding binary numbers works just like adding denary, but the only digits are 0 and 1. The carry rules are simple:
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 + carry 1 | 1 | 1 |
Check: 108 + 53 = 161. And 10100001 in binary is 128 + 32 + 1 = 161. Correct.
Negative numbers: two's complement
So far we have only looked at positive numbers. But computers need to store negative numbers too. The standard method is called two's complement.
In two's complement, the leftmost bit is the sign bit. If it is 0, the number is positive. If it is 1, the number is negative. But the negative value is not simply applied: the whole system shifts so that the column header for the leftmost bit becomes negative.
For an 8-bit two's complement number, the column headers become:
-128 + 16 + 8 + 4 + 2 + 1 = -97
Converting a positive number to its negative two's complement
Check: -128 + 64 + 16 + 2 = -46. Correct.
The range of an 8-bit two's complement number is -128 to +127. Notice it is not symmetrical: there is one more negative value than positive. This is a property of two's complement that comes up in exam questions.
Hexadecimal (base 16)
Binary is precise but hard to read. The number 11111010001011000 is difficult to scan, easy to miscount, and painful to type. Computers and programmers needed a more compact notation.
Hexadecimal is base 16. It uses 16 digits: 0-9 and then A-F (where A=10, B=11, C=12, D=13, E=14, F=15). One hex digit represents exactly four binary digits (a nibble), which makes conversion between the two trivial.
| Denary | Binary | Hex |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Binary to hex
Group the binary digits into nibbles (groups of 4) from the right, then convert each nibble using the table above.
Hex in the real world: colour codes
Colours on screens are defined by three values: Red, Green, and Blue, each ranging from 0 to 255. Because 255 = FF in hex, two hex digits are enough for each channel. A web colour like #4ADE80 means:
= 74
= 222
= 128
combined
Hex is also used for memory addresses, MAC addresses, IPv6 addresses, and error codes. You will encounter it throughout the course.
0x in code (like 0xFF), that is a convention telling you the number is in hexadecimal. The prefix is not part of the value, just a signal to the reader and the compiler. 0xFF = 255 in denary.Bits, bytes, and beyond
A single binary digit is a bit. Eight bits make a byte. From there, units scale up, but there is an important wrinkle: there are two competing systems.
| Name | Symbol | Decimal definition | Binary definition |
|---|---|---|---|
| Kilobyte | KB | 1,000 bytes | 1,024 bytes (= 2¹&sup0;) |
| Megabyte | MB | 1,000,000 bytes | 1,048,576 bytes (= 2²&sup0;) |
| Gigabyte | GB | 1,000,000,000 bytes | 1,073,741,824 bytes (= 2³&sup0;) |
| Terabyte | TB | 1,000,000,000,000 bytes | 1,099,511,627,776 bytes (= 2&sup4;&sup0;) |
Hard drive manufacturers use the decimal definitions (so their drives look bigger). Operating systems historically used the binary definitions (so your OS reports a smaller number for the same drive). This is why a "500 GB" hard drive shows as roughly 465 GB in Windows.
The binary-based units have their own names to avoid ambiguity: kibibyte (KiB), mebibyte (MiB), gibibyte (GiB). You will see these in technical documentation, and OCR expects you to know the distinction.
Practice questions
Try each question yourself before revealing the answer.
10110011 from binary to denary.
01100111 + 00101010 in binary. Give your answer in binary and denary.
B7 from hexadecimal to binary and denary.
#FF6B00. What are the red, green, and blue values in denary?