Hexadecimal & Octal
Binary's shorthand

Key ideas
- Binary gets long very fast
- Easy to misread
- We need a shorthand
- Hexadecimal = base 16
- Digits: 0–9, then A–F
- A = 10 … F = 15
- 16 = 2⁴
- 1 hex digit = exactly 4 bits
- 1 byte = 2 hex digits
- Octal = base 8, digits 0–7
- 1 octal digit = 3 bits
- Seen in Linux permissions: 755
Worked example
- Hex place values: 1, 16, 256 …
- F = 15
- 2F in hex = 47
- What if the bits don't divide evenly? Take this nine bit number. Group in fours, starting from the right. The last group has only one bit, so pad it with zeros on the left. Now read each group. One, A, F.
- Back to our colour code. F F is two hundred fifty five, the maximum red. Green is zero. Blue is zero. So the colour is pure red.
See the answer in Lesson 4 →
Full lesson text
Read everything said in the video
Where you have seen itFirst, last lesson's question. One one one one one is sixteen, plus eight, plus four, plus two, plus one. Thirty one.
Where you have seen itHave you ever seen a colour code like this? Hash, F F, zero zero, zero zero. It means pure red. But why are there letters inside a number? Because it's written in hexadecimal.
The ideaBinary is perfect for computers, but hard for humans. Even two hundred fifty five needs eight digits. Long strings of ones and zeros are easy to misread. So engineers use a shorthand.
The ideaHexadecimal is base sixteen, so it needs sixteen digits. Zero to nine, and then the letters A to F, which stand for ten to fifteen.
The ideaHere's why engineers love it. Sixteen is two to the power four, so one hex digit is exactly four bits. Split the bits into groups of four. One zero one one is eleven, which is B. The second group, zero one one zero, is six. So this whole byte is just B six.
Worked exampleNow let's convert hex two F to decimal. The place values are powers of sixteen. Two times sixteen is thirty two. F is fifteen, times one. Thirty two plus fifteen is forty seven.
Worked exampleWhat if the bits don't divide evenly? Take this nine bit number. Group in fours, starting from the right. The last group has only one bit, so pad it with zeros on the left. Now read each group. One, A, F.
Worked exampleBack to our colour code. F F is two hundred fifty five, the maximum red. Green is zero. Blue is zero. So the colour is pure red.
The ideaOctal is the same idea in base eight. Digits zero to seven, and each octal digit is exactly three bits. One zero one is five. One one zero is six. You'll see octal in Linux file permissions, like seven five five.
Common mistakeA common mistake is grouping the bits from the left. That gives a wrong answer whenever the length isn't a multiple of four. Always group from the right, and pad zeros on the left.
Memory trickHere's a memory trick. F means full. All four bits are one, which is fifteen. And remember, sixteen is two to the power four, so hex takes four bits. Eight is two to the power three, so octal takes three.
RecapLet's recap. Hexadecimal is base sixteen, with digits zero to nine and A to F. One hex digit equals four bits. Octal is base eight, and one octal digit equals three bits. And always group from the right.
RecapQuick question. What is one zero one zero, one one zero zero, in hexadecimal? The answer is in the next lesson.
Ready to test yourself? Practise real digital electronics interview questions, with model answers.
Practice questions →← All 33 lessons of the Digital Electronics course
Last updated