What is Hexadecimal?
Hexadecimal (often shortened to hex) is a number system that uses 16 symbols instead of the usual 10. It counts: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
After 9, we use letters:
| Decimal | Hex | Binary |
|---|---|---|
| 10 | A | 1010 |
| 11 | B | 1011 |
| 12 | C | 1100 |
| 13 | D | 1101 |
| 14 | E | 1110 |
| 15 | F | 1111 |
Hex numbers are often written with a 0x prefix or a # symbol to show they are hexadecimal — for example, 0xFF or #FF0000 (the colour red in HTML).
Why Do We Use Hexadecimal?
Binary numbers get very long very quickly. The decimal number 255 in binary is 11111111 — eight digits. In hexadecimal it is simply FF — just two digits.
Each hex digit represents exactly 4 binary bits (called a nibble). This makes converting between hex and binary very easy, and it makes long binary numbers much more readable for humans.
Converting Between Hex and Binary
To convert binary to hex, split the binary number into groups of 4 bits from the right, then replace each group with its hex digit.
Example: Convert 11010110 to hex.
- Split: 1101 0110
- 1101 = 13 = D
- 0110 = 6 = 6
- Result: D6
To go the other way, replace each hex digit with its 4-bit binary pattern:
- D = 1101, 6 = 0110
- Result: 11010110
Hex in Real Life
You will see hexadecimal everywhere in computing:
- Colours in HTML/CSS:
#FF5733means Red=FF (255), Green=57 (87), Blue=33 (51) - Memory addresses: RAM locations are shown in hex, e.g.
0x7FFF1234 - Error codes: Windows "Blue Screen" errors show hex codes like
0x0000007E
When you see a colour code like #3A9FD2 in a web page, you can now read it! #3A is red, #9F is green, and #D2 is blue — all in hexadecimal.
Converting Hex to Decimal
To convert a two-digit hex number to decimal, multiply the left digit by 16 and add the right digit.
Example: B4 in decimal = (11 × 16) + 4 = 176 + 4 = 180.
Practice Problems
Convert the binary number 10111001 to hexadecimal. Show your working by splitting into nibbles.
Show answer
A web designer uses the HTML colour #00FF00. What colour is this, and what are the decimal values of its red, green, and blue components?