- Practice
- About 13 min
- 5 practice questions
Hexadecimal shortcuts and colour codes
Convert two-digit hex numbers to decimal and back in seconds and read the hex colour codes used on web pages.
If something looks wrong, please tell us.
Hexadecimal is shorthand for binary, which is why it appears in memory addresses, error codes and colour codes on web pages. Exams ask short conversions, and a few quick habits make them easy. Because 16 is 2 to the power 4, every hex digit stands for exactly four bits.
The sixteen digits
| Hex | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| Decimal | 10 | 11 | 12 | 13 | 14 | 15 |
Two-digit hex to decimal
A two-digit hex number has a left digit (sixteens) and a right digit (ones). The decimal value is 16 × left + right. Remember that FF is 16 × 15 + 15 = 255, the largest value of two hex digits, which equals eight ones in binary.
Decimal to two-digit hex
Divide by 16. The quotient is the left digit and the remainder is the right digit. Convert any value from 10 to 15 into a letter.
Hex colour codes
A web colour is written as a hash sign followed by six hex digits: two for red, two for green and two for blue. Each pair runs from 00 (none of that colour) to FF (full strength), which is 0 to 255 in decimal. The number of different colours is 256 × 256 × 256 = 16,777,216.
| Code | Red | Green | Blue | Colour |
|---|---|---|---|---|
| #FF0000 | 255 | 0 | 0 | Red |
| #00FF00 | 0 | 255 | 0 | Green |
| #0000FF | 0 | 0 | 255 | Blue |
| #FFFFFF | 255 | 255 | 255 | White |
| #000000 | 0 | 0 | 0 | Black |
Worked examples
Example 1. Convert 3C to decimal. C is 12, so 3 × 16 + 12 = 48 + 12 = 60. And B7 = 11 × 16 + 7 = 176 + 7 = 183.
Example 2. Convert 200 to hexadecimal. 200 divided by 16 is 12 remainder 8. The quotient 12 is C, so 200 = C8. Check: 12 × 16 + 8 = 192 + 8 = 200.
Example 3. Convert the binary number 10100111 to hexadecimal. Split into nibbles: 1010 and 0111. They are A (ten) and 7. The answer is A7, which is 10 × 16 + 7 = 167 in decimal.
Example 4. What are the red, green and blue values of #FF8000? The pairs are FF, 80 and 00. FF is 255, 80 is 8 × 16 = 128 and 00 is 0. So the colour is (255, 128, 0), full red, half green and no blue: an orange.
Example 5. A memory location is given as 1F4 in hexadecimal. Its decimal value is 1 × 256 + 15 × 16 + 4 = 256 + 240 + 4 = 500.
Example 6. Which is greater, 7F or 80? Do not compare them as words. 7F = 7 × 16 + 15 = 112 + 15 = 127, while 80 = 8 × 16 = 128. So 80 is greater by exactly 1, because adding 1 to 7F makes F roll over to 0 and carries into the left digit.
Left digit times 16 plus right digit. Each hex digit is four bits. FF is 255.
Key takeaways. Two hex digits make one byte. Convert with 16 × left + right, and back by dividing by 16. A colour code is three bytes: red, green and blue.
Check your understanding
-
1. What is the decimal value of the hexadecimal number B7?
- 171
- 183
- 167
- 187
Show answer
Answer: B. B is 11, so 11 × 16 + 7 = 176 + 7 = 183.
-
2. Which hexadecimal number equals decimal 200?
- C8
- B8
- C6
- D4
Show answer
Answer: A. 200 divided by 16 gives 12 remainder 8. The quotient 12 is C, so 200 = C8.
-
3. The colour code #0000FF has full strength in which colour?
- Red
- Green
- Blue
- White
Show answer
Answer: C. The three pairs are red, green and blue in that order. The pair 00 00 FF leaves only the blue pair at full value.
-
4. Convert the binary number 10100111 to hexadecimal.
- 9A
- A9
- 7A
- A7
Show answer
Answer: D. The nibbles are 1010 = A and 0111 = 7, giving A7.
-
5. How many different colours can the six-digit hex colour system describe?
- 16,777,216
- 65,536
- 1,000,000
- 4,096
Show answer
Answer: A. Each of the three bytes has 256 values, so 256 × 256 × 256 = 16,777,216.
Sign in to keep track of the lessons you finish.