CS Fundamentals
Learn the hexadecimal (base-16) number system — its digits, conversions to/from binary and decimal, and why programmers use it extensively.
Introduction
If you have ever seen strange-looking codes like #FF5733 (a color code), 0x1A3F (a memory address), or 4B:6F:6C:6B:61:74:61 (a MAC address), you have encountered hexadecimal numbers. Hexadecimal — often shortened to "hex" — is a base-16 number system that uses sixteen symbols: the digits 0 through 9 and the letters A through F. It might seem odd to use letters as numbers, but hexadecimal exists for a very practical reason: it is the most human-friendly way to represent binary data.
Computers work in binary (base-2), but binary numbers are very long and hard for humans to read. The number 255 in binary is 11111111 — eight digits for a relatively small number. In hexadecimal, the same number is simply FF — just two characters. Hexadecimal provides a compact, readable shorthand for binary that programmers, network engineers, and system administrators use every day.
Why Base-16?
The choice of 16 as a base is not arbitrary — it has a perfect mathematical relationship with binary. Since 16 is 2 raised to the power of 4 (2^4 = 16), each hexadecimal digit corresponds to exactly 4 binary digits (bits). This means you can convert between hex and binary by simply looking at groups of 4 bits, without any calculation.
Compare this to decimal: converting between decimal and binary requires division and multiplication. But hex-to-binary is instant: each hex digit becomes exactly 4 bits. This one-to-one correspondence makes hexadecimal the preferred notation for binary data in computing.
Hexadecimal Digits
The hexadecimal system uses 16 symbols. The first ten are the familiar decimal digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. For values 10 through 15, we use letters: A represents 10, B represents 11, C represents 12, D represents 13, E represents 14, and F represents 15.
So counting in hexadecimal goes: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, 12... The number "10" in hex is not ten — it is sixteen (1 group of 16 plus 0 ones). The number "1F" in hex means 1 group of 16 plus F (15) ones = 31 in decimal.
To avoid confusion with decimal numbers, hexadecimal values are often prefixed with "0x" in programming (0xFF, 0x1A) or suffixed with "h" (FFh, 1Ah) or preceded with a hash symbol in web colors (#FF5733).
Converting Hexadecimal to Decimal
To convert a hex number to decimal, multiply each digit by 16 raised to the power of its position (starting from 0 on the right) and sum the results.
Example: Convert 2B7 (hex) to decimal. The rightmost digit 7 is in position 0: 7 × 16^0 = 7 × 1 = 7. The middle digit B (which equals 11) is in position 1: 11 × 16^1 = 11 × 16 = 176. The leftmost digit 2 is in position 2: 2 × 16^2 = 2 × 256 = 512. Sum: 512 + 176 + 7 = 695. So 2B7 in hex equals 695 in decimal.
Example: Convert FF (hex) to decimal. F (15) × 16^1 = 240. F (15) × 16^0 = 15. Sum: 240 + 15 = 255. FF hex = 255 decimal. This is why 255 appears frequently in computing (it is the maximum value of one byte — 8 bits — represented as two hex digits).
Converting Decimal to Hexadecimal
To convert a decimal number to hex, repeatedly divide by 16, recording the remainders. The remainders, read from bottom to top, form the hexadecimal number.
Example: Convert 450 to hexadecimal. 450 ÷ 16 = 28 remainder 2. 28 ÷ 16 = 1 remainder 12 (which is C). 1 ÷ 16 = 0 remainder 1. Reading remainders from bottom to top: 1C2. So 450 decimal = 1C2 hexadecimal.
Converting Between Hexadecimal and Binary
This is where hexadecimal truly shines — conversion is instant with no calculation needed.
Hex to Binary: Replace each hex digit with its 4-bit binary equivalent. A = 1010, F = 1111, 3 = 0011, etc. Example: 3FA hex = 0011 1111 1010 binary (just substitute each digit).
Binary to Hex: Group the binary number into groups of 4 bits from the right, then replace each group with its hex equivalent. Example: 1101 0110 binary = D6 hex (1101 = D, 0110 = 6).
This instant conversion is why hexadecimal is used — it is effectively a shorthand notation for binary.
Real-World Uses of Hexadecimal
Color codes in web design use hex: #RGB where each pair represents Red, Green, Blue intensity from 00 (none) to FF (maximum). The color #FF0000 is pure red (max red, no green, no blue). #FFFFFF is white (all colors at maximum). #000000 is black (all colors at zero).
Memory addresses are displayed in hex because they are shorter and easier to read than binary. A 32-bit address like 0xC0A80164 is far more readable than its binary equivalent 11000000101010000000000101100100.
MAC addresses (hardware network addresses) use hex: 4B:6F:6C:6B:61:74:61. Assembly language and low-level programming use hex to represent byte values, opcodes, and data.
Key Takeaways
- Hexadecimal is base-16, using digits 0-9 and letters A-F (representing 10-15)
- It exists because each hex digit maps to exactly 4 binary bits — providing compact binary representation
- Hex-to-binary conversion is instant: replace each hex digit with its 4-bit pattern
- Decimal-to-hex uses repeated division by 16; hex-to-decimal uses positional multiplication
- Real-world uses: color codes (#FF5733), memory addresses (0xC0A80164), MAC addresses
- FF hex = 255 decimal = 11111111 binary — the maximum value of one byte
- Hexadecimal is a display format, not a separate number — FF, 255, and 11111111 are the same value
- Practice conversions until they become automatic — this is heavily tested in exams
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Hexadecimal Number System — Computer Fundamentals.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Fundamentals topic.
Search Terms
computer-fundamentals, computer fundamentals, computer, fundamentals, data, representation, hexadecimal, number
Related Computer Fundamentals Topics