Number Bases: Binary, Octal and Hexadecimal
What is Number Bases: Binary, Octal and Hexadecimal? · about 14 min
No animation attached yet; learners read the lesson text below.
Key points
Number bases: The base of a number system is the number of different digits it uses and how much each place is worth: binary 2, octal 8, denary 10 and hexadecimal 16.
Any base to denary: To change a number from any base into denary, replace letters with their values, multiply each digit by its place value and add.
Repeated division: To convert denary to another base, divide by the new base again and again, write each remainder until the quotient is 0 and read the remainders from the bottom up.
Letters for remainders: In base 16, remainders from 10 to 15 must be written as the letters A to F, so 12 is written as C.
Grouping bits: Each octal digit is exactly three binary bits and each hexadecimal digit is exactly four bits, a nibble; group from the right and add leading zeros if a group is short.
Web colour codes: A web colour code such as #0B6E4F is three pairs of hex digits for red, green and blue, each pair being eight bits.
Binary addition: Binary addition follows four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1).
Binary subtraction: In binary subtraction, 0 − 1 needs a borrow: borrowing 1 from the next column gives 2 in the current column, so 10 − 1 = 1.
Key words
- base
The number of different digits a number system uses, such as 2 for binary and 16 for hexadecimal.
- denary
The base 10 number system that we use every day, with the digits 0 to 9.
- octal
The base 8 number system; each octal digit equals exactly three binary bits.
- hexadecimal
The base 16 number system, using 0 to 9 and the letters A to F for 10 to 15.
- nibble
A group of four bits, equal to one hexadecimal digit.
- carry
The 1 moved to the next column in binary addition, as when 1 + 1 = 10.
Computing · Basic 8 / JHS 2 · Strand 1: Introduction To Computing
This lesson has 4 short films. Read each chapter or watch the film, then work through Explore, Experiment, Play, Apply and Review.
Film 1: The Colour Code
Bases 2, 8, 10 and 16 into denary
Scene: The ICT Club · A Website for Prize-Giving Day
Esi: I wanted the headings in the school's dark green. The colour box asked for a code like hash zero B six E four F. What kind of number has letters in it?
Mrs Owusu: Count to sixteen with only one digit: zero to nine, then A to F. That is hexadecimal, and computers love it.
Four Number Bases
Binary, base two, uses only zero and one, and its places are sixty-four, thirty-two, sixteen, eight, four, two, one. Octal, base eight, uses the digits zero to seven, and its places are five hundred and twelve, sixty-four, eight, one. Denary, base ten, uses the digits zero to nine, and its places are one thousand, one hundred, ten, one. Hexadecimal, base sixteen, uses zero to nine and then the letters A to F, and its places are four thousand and ninety-six, two hundred and fifty-six, sixteen, one. In every base, each place is worth the base multiplied by the place to its right.
Hexadecimal 2F to Denary and Binary
To change hexadecimal two F to denary, multiply each digit by its place value: two times sixteen plus F times one. First replace the letter with its value: F is fifteen. So it is thirty-two plus fifteen. That is forty-seven in denary. For binary, write each hex digit as four bits: two is nought-nought-one-nought, and F is one-one-one-one. So two F is forty-seven in denary and nought-nought-one-nought one-one-one-one in binary.
Octal 113 to Denary
To change octal one-one-three to denary, multiply each digit by its place value: one times sixty-four, one times eight and three times one. That is sixty-four plus eight plus three. That is seventy-five in denary. So one-one-three in octal is seventy-five in denary.
Key ideas
- Number bases: The base of a number system is the number of different digits it uses and how much each place is worth: binary 2, octal 8, denary 10 and hexadecimal 16.
- Any base to denary: To change a number from any base into denary, replace letters with their values, multiply each digit by its place value and add.
Think about it: How many digits does each base use: binary, octal, denary, hexadecimal? Convert to denary: (a) 57 base 8, (b) 3A base 16, (c) FF base 16, (d) 1100100 base 2.
Model answer: Binary 2 digits, octal 8, denary 10, hexadecimal 16. (a) 47. (b) 58. (c) 255. (d) 100.
Film 2: Dividing by the Base
Repeated division into hex, octal and binary
Scene: The Prize-Giving Colour · 156
Kwame: How do I write one hundred and fifty-six in hexadecimal?
Mrs Owusu: Use the repeated division you learned for binary, but divide by the new base. Remainders from ten to fifteen are written as letters.
156 to Hexadecimal
One hundred and fifty-six divided by sixteen is nine remainder twelve, and twelve is written as C. Nine divided by sixteen is nought remainder nine. The quotient is nought, so we stop. Reading the remainders from the bottom up gives nine C. Check: nine times sixteen plus twelve is one hundred and forty-four plus twelve, which is one hundred and fifty-six. So one hundred and fifty-six in denary is nine C in hexadecimal.
75 to Octal
Seventy-five divided by eight is nine remainder three. Nine divided by eight is one remainder one. One divided by eight is nought remainder one, so we stop. Reading the remainders upwards gives one-one-three. That matches the earlier example, where one-one-three in octal was seventy-five.
200 in Three Bases
In binary, two hundred is one hundred and twenty-eight plus sixty-four plus eight, which is one-one-zero-zero-one-zero-zero-zero. In octal, two hundred divided by eight is twenty-five remainder nought, twenty-five divided by eight is three remainder one, and three divided by eight is nought remainder three. Reading upwards gives three-one-zero. In hexadecimal, two hundred divided by sixteen is twelve remainder eight, and twelve divided by sixteen is nought remainder twelve, which is C. So it is C eight. So two hundred is eleven million, one thousand and eight in binary, three-one-zero in octal and C eight in hex.
Key ideas
- Repeated division: To convert denary to another base, divide by the new base again and again, write each remainder until the quotient is 0 and read the remainders from the bottom up.
- Letters for remainders: In base 16, remainders from 10 to 15 must be written as the letters A to F, so 12 is written as C.
Think about it: Convert 200 to (a) binary, (b) octal, (c) hexadecimal. In base 16, how are remainders from 10 to 15 written?
Model answer: (a) 11001000. (b) 310. (c) C8. Remainders from 10 to 15 are written as the letters A to F.
Film 3: Threes and Fours
Binary to octal and hexadecimal in one step
Scene: The Website Builder · A Long Binary String
Esi: A colour is really twenty-four zeros and ones, but the builder wants only six characters.
Mrs Owusu: Because eight is two cubed and sixteen is two to the fourth, binary groups neatly into threes for octal and fours for hexadecimal.
Grouping 10011100
To convert one-zero-zero-one-one-one-zero-zero to octal, group the bits in threes from the right: one-zero, nought-one-one, one-zero-zero, and pad the first group to nought-one-zero. Nought-one-zero is two, nought-one-one is three and one-zero-zero is four. To convert it to hexadecimal, group the bits in fours from the right: one-zero-zero-one and one-one-zero-zero. A group of four bits is called a nibble. One-zero-zero-one is nine, and one-one-zero-zero is twelve, which is C. So the number is two-three-four in octal and nine C in hexadecimal.
A Web Colour Code
The colour code hash zero B six E four F is three pairs of hex digits. The first pair, zero B, stands for red, and is eight bits. The second pair, six E, stands for green, and is eight bits. The third pair, four F, stands for blue, and is eight bits. This is why web designers use hex: a long string of twenty-four zeros and ones becomes just six easy characters.
Group From the Right
The first mistake: group the binary digits from the left. Check that idea. Always start from the right-hand end. For one-one-zero-one-zero-one, grouping from the left as one-one-zero-one and nought-one gives the wrong answer. From the right it is one-one and nought-one-zero-one, which becomes nought-nought-one-one and nought-one-zero-one, which is three-five in hex. Start from the right. The second mistake: each hex digit is three bits. Check that idea. Each hex digit is four bits, and each octal digit is three bits. Hex four, octal three.
Key ideas
- Grouping bits: Each octal digit is exactly three binary bits and each hexadecimal digit is exactly four bits, a nibble; group from the right and add leading zeros if a group is short.
- Web colour codes: A web colour code such as #0B6E4F is three pairs of hex digits for red, green and blue, each pair being eight bits.
Think about it: Use the grouping shortcut to convert 11011010 base 2 to octal and to hexadecimal. Convert B7 base 16 to binary. The web colour code for white is #FFFFFF: what is the denary value of each pair FF, and what does that tell you?
Model answer: Octal: 011 011 010 = 332. Hex: 1101 1010 = DA. B7 = 1011 0111. FF = 255, the maximum, so white is full red, green and blue.
Film 4: Carry and Borrow in Binary
Adding and subtracting base 2
Scene: A Computer's ALU · Adding Two Numbers
Kwame: Inside the ALU, every sum is done in binary. How does it add one and one?
Mrs Owusu: One plus one makes two, which in binary is written one-zero. You write zero and carry one, just as in denary six plus seven makes thirteen.
The Rules of Binary Addition
Nought plus nought is nought. Nought plus one, and one plus nought, are both one. One plus one is one-zero: write nought and carry one. One plus one plus one is one-one: write one and carry one. The key rule is that one plus one makes two, which in binary is written one-zero.
Adding 1011 and 110
Line the numbers up on the right and add column by column from the right. Column one is one plus nought, which is one. Column two is one plus one, which is one-zero: write nought and carry one. Column three is nought plus one plus the carried one, which is one-zero: write nought and carry one. Column four is one plus nought plus the carried one, which is one-zero: write nought and carry one. Column five is just the final carry, one. The answer is one-zero-zero-zero-one. Check in denary: eleven plus six is seventeen, which is sixteen plus one, and that is one-zero-zero-zero-one.
Subtracting 110 From 1101
Column one is one minus nought, which is one. Column two is nought minus one, so borrow from column three: ten minus one is one. Column three lent a one, so it is now nought minus one, and it borrows from column four: ten minus one is one. Column four lent a one, so it is nought minus nought, which is nought. The answer is nought-one-one-one. Check in denary: thirteen minus six is seven, which is one-one-one.
Key ideas
- Binary addition: Binary addition follows four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1).
- Binary subtraction: In binary subtraction, 0 − 1 needs a borrow: borrowing 1 from the next column gives 2 in the current column, so 10 − 1 = 1.
Think about it: Add (a) 101 + 11, (b) 1110 + 1011 in binary and check each in denary. Subtract (a) 1010 − 11, (b) 10000 − 1.
Model answer: (a) 101 + 11 = 1000 (5 + 3 = 8). (b) 1110 + 1011 = 11001 (14 + 11 = 25). 1010 − 11 = 111 (10 − 3 = 7). 10000 − 1 = 1111 (16 − 1 = 15).
Want to keep your progress?
Create a free account to earn points and build a streak.
