Year 10 · Computer Science · Autumn 1
Data representation · Lesson 1 of 5
Binary, denary and hex: conversions
Theory1.1 Number systems
Year 10 · Computer Science · Data representation · Lesson 1 of 5
You will learn to
- Convert positive whole numbers between binary and denary, both ways, showing working.
- Convert between hexadecimal and binary, using one hex digit for each group of four bits.
- Convert between hexadecimal and denary, both ways.
- Explain why hexadecimal is used, with two real uses, such as colour codes and MAC addresses.
Year 10 · Computer Science · Data representation · Lesson 1 of 5
Success criteria
You have got it when you can say:
- I can convert 10110101 to denary and 200 to binary, with my working shown.
- I can convert 3F to binary and to denary.
- I can give two reasons why people use hex instead of binary.
Year 10 · Computer Science · Data representation · Lesson 1 of 5
Key words (1 of 3)
- Bit
- A single binary digit, 0 or 1.
- Nibble
- A group of 4 bits, which matches one hexadecimal digit.
- Byte
- A group of 8 bits.
- Denary
- The base 10 number system we use every day, with digits 0 to 9.
Year 10 · Computer Science · Data representation · Lesson 1 of 5
Key words (2 of 3)
- Binary
- The base 2 number system computers use, with digits 0 and 1.
- Hexadecimal
- The base 16 number system, with digits 0 to 9 and A to F, used to write binary in a short form.
- Overflow
- An error when a result is too big to fit in the number of bits available.
- Logical shift
- Moving all the bits left or right, losing bits off one end and filling the other end with 0s.
Year 10 · Computer Science · Data representation · Lesson 1 of 5
Key words (3 of 3)
- Two's complement
- A way to store negative numbers, where the leftmost bit has a negative place value (−128 in 8 bits).
- Colour depth
- The number of bits used to store the colour of each pixel.
The explanation · step 1 of 15 · part 1 of 2
Why computers use binary
A computer is made of billions of tiny switches called transistors. Each switch is either off or on.
We write off as 0 and on as 1. A number system with only two digits is called binary.
One binary digit is a bit. Eight bits together make a byte.
Every extra bit doubles the number of different patterns you can make.
The explanation · step 1 of 15 · part 2 of 2
Why computers use binary (continued)
Two states are very reliable. A switch is clearly on or clearly off, so the computer rarely misreads a value.
The explanation · step 1 of 15
The maths: How many patterns can n bits make?
The explanation · step 2 of 15 · part 1 of 3
Place value: denary and binary
Denary is our everyday number system. It has ten digits, 0 to 9, and each column is worth 10 times the column to its right.
Binary works the same way, but each column is worth 2 times the column to its right.
For 8 bits the column values, from left to right, are 128, 64, 32, 16, 8, 4, 2, 1.
To turn binary into denary, add up the column values that have a 1 under them.
The explanation · step 2 of 15 · part 2 of 3
Place value: denary and binary (continued)
Try the toy: switch on the 128 bit. What happens to the denary value? Now make 255.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
The explanation · step 2 of 15 · part 3 of 3
Place value: denary and binary (continued)
Always write the column values above the bits first. Most mistakes come from adding the wrong column.
There is something to try for this step in the IGCSE library.
The explanation · step 3 of 15 · part 1 of 2
Denary to binary
Start at the left column, 128. Ask: does 128 fit into my number?
If it fits, write 1 and take 128 away. If it does not fit, write 0.
Move to the next column and repeat with what is left. Stop when you reach the 1 column.
Always write all 8 bits, including the 0s at the front.
The explanation · step 3 of 15 · part 2 of 2
Denary to binary (continued)
Each column is used once at most, so taking away the biggest column first always gives the right pattern.
The explanation · step 4 of 15 · part 1 of 2
The biggest number n bits can hold
With n bits you get 2ⁿ patterns. One of those patterns is 0.
So the biggest number is one less than the number of patterns: 2ⁿ − 1.
8 bits hold 0 to 255. 16 bits hold 0 to 65,535.
A register is a small store inside the processor. An 8-bit register cannot hold anything bigger than 255.
The explanation · step 4 of 15 · part 2 of 2
The biggest number n bits can hold (continued)
8 bits give 256 different values, but the largest value is 255, because counting starts at 0.
The explanation · step 6 of 15 · part 1 of 2
Hex to denary and denary to hex
Hex to denary: multiply each digit by its column value, then add. Change letters to numbers first (B = 11, F = 15).
Denary to hex: divide by 16. The whole-number answer is the left digit. The remainder is the right digit.
Change any digit from 10 to 15 into its letter.
The explanation · step 6 of 15 · part 2 of 2
Hex to denary and denary to hex (continued)
A remainder of 10 to 15 must be written as a letter. Writing "128" for C8 is a common slip.
The explanation · step 6 of 15
The maths: Hex to denary
The explanation · 10 more steps
More on the lesson page
The lesson page has the rest of the explanation, step by step:
- Hexadecimal: base 16
- Binary and hex using nibbles
- Why hexadecimal is used
- Adding binary: the four rules
- A full 8-bit addition
- Overflow
- Logical left shift
- Logical right shift
- Two's complement: negative numbers
- Denary to two's complement
Year 10 · Computer Science · Data representation · Lesson 1 of 5
The maths: Binary to denary, as a formula
Symbols first, then the words, then the equation. Change the numbers.
Year 10 · Computer Science · Data representation · Lesson 1 of 5
Quick quiz · 1 of 3
How many bits are in a byte?
- A 4
- B 16
- C 8
C. 8
A byte is 8 bits. 4 bits is a nibble.
Year 10 · Computer Science · Data representation · Lesson 1 of 5
Quick quiz · 2 of 3
Hex B2 in binary is…
- A 1011 0010
- B 1100 0010
- C 1011 0100
A. 1011 0010
B = 11 = 1011 and 2 = 0010. One hex digit is 4 bits.
Year 10 · Computer Science · Data representation · Lesson 1 of 5
Quick quiz · 3 of 3
Adding 11001100 and 01011010 in an 8-bit register gives…
- A 11111111
- B An overflow error
- C 00100110 with no problem
B. An overflow error
The true answer needs 9 bits (100100110). The ninth bit does not fit.
Year 10 · Computer Science · Data representation · Lesson 1 of 5
Exit ticket
Answer on paper before you go. Then check.
Shifting 00001010 (10) one place left gives…
A 00000101 (5)B 00001011 (11)C 00010100 (20)
C. 00010100 (20) A left shift doubles. 10 becomes 20.
In 8-bit two's complement, 11111111 is…
A −127B 255C −1
C. −1 The left bit is worth −128. −128 + 127 = −1.