Detailed · Deep study
1Why computers use binary
A computer's processor and memory are built from billions of tiny switches (transistors) arranged as logic gates and stored in registers. Each switch has only two states – on or off – which are represented by 1 and 0. So any data a computer processes – numbers, characters, sounds, images, instructions – must first be converted into binary.
2Denary, binary and hexadecimal
| System | Base | Digits | Place values (right to left) |
|---|---|---|---|
| denary | 10 | 0–9 | 1, 10, 100, 1000, … |
| binary | 2 | 0, 1 | 1, 2, 4, 8, 16, 32, 64, 128, … |
| hexadecimal | 16 | 0–9, A–F | 1, 16, 256, 4096 |
Worked example
Denary to binary
Convert 200 to 8-bit binary.
- 1
Subtract the largest place value that fits, working left to right.
, ,
- 2
Put 1 under 128, 64 and 8; 0 elsewhere.
Answer11001000
| Denary | Binary | Hexadecimal |
|---|---|---|
| 0 | 0000 | 0 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Worked example
Denary to hexadecimal
Convert 173 to hexadecimal.
- 1
Divide by 16.
- 2
10 → A, 13 → D.
AnswerAD
Worked example
Hexadecimal to binary
Convert 3F to binary.
- 1
Each digit to 4 bits.
3 → 0011, F → 1111
Answer00111111
3Why hexadecimal is used
Hexadecimal is a shorter way of writing binary: one hex digit replaces four bits, so it is easier for humans to read, write and remember, with fewer errors. The computer still stores binary.
| Use of hexadecimal | Example |
|---|---|
| colour codes in HTML/CSS | #FF8000 (red FF, green 80, blue 00) |
| MAC addresses | 00:1A:2B:3C:4D:5E |
| memory dumps and debugging | showing the contents of memory locations |
| error codes | e.g. 0x0000007B |
| IPv6 addresses | 2001:0db8:… |
4Binary addition and overflow
| Sum | Result | Carry |
|---|---|---|
| 0 + 0 | 0 | 0 |
| 0 + 1 | 1 | 0 |
| 1 + 1 | 0 | 1 |
| 1 + 1 + 1 | 1 | 1 |
Add two 8-bit numbers column by column from the right, carrying 1 to the next column when needed. A device has a predefined limit for what it can store (8 bits: 0–255; 16 bits: 0–65 535). If the result is larger, the final carry has nowhere to go: an overflow error occurs and the stored answer is wrong.
5Logical binary shifts
- A logical left shift of places multiplies a positive number by ; a logical right shift divides by .
- Bits shifted off the end of the register are lost; zeros are shifted in at the other end.
- If a 1 is lost from the left (most significant bit), the multiplication is no longer correct; if a 1 is lost from the right, the division is not exact.
Worked example
Shift
Perform a logical left shift of two places on 00110101. What is the effect?
- 1
Move every bit two places left; fill with zeros.
11010100
- 2
Check.
53 → 212 = 53 × 4
Answer11010100; the value is multiplied by 4
6Two's complement
In 8-bit two's complement the most significant bit has place value −128, so a 1 in that position means the number is negative. The range is −128 to +127.
- Negative denary → two's complement: write the positive value in binary, flip every bit (0↔1), then add 1.
- Two's complement → denary: add the place values, counting the MSB as −128.
Worked example
Convert to denary
Convert the two's complement number 10011010 to denary.
- 1
Place values.
Answer−102
7Exam focus
Key words: binary; denary; hexadecimal; nibble; place value; MSB; LSB; overflow; logical shift; two's complement.
Quick self-check
Answer in your head first, then reveal.
174 (1).
00101101 (1).
Shorter than binary / easier to read (1); fewer mistakes when writing or remembering (1).
1 00010011 (1); overflow – result 275 is greater than 255 (1).
Divides by 8 (bits lost from the right) (1).
45 = 00101101 (1); flip 11010010, add 1: 11010011 (1).
