Numbers are the foundation of mathematics and everyday life. But did you know that the way we write numbers depends on a system called a number system? A number system defines how numbers are represented using a set of symbols and a base or radix. The most familiar number system is the decimal system, which uses base 10 and digits from 0 to 9.
However, in fields like computing and digital electronics, other number systems are more practical. This is because computers work with binary data (base 2), which can be long and hard to read. To simplify this, number systems like octal (base 8) and hexadecimal (base 16) are used.
Among these, the hexadecimal system is especially important. It is widely used in programming, memory addressing, and digital color representation. Understanding hexadecimal helps you read and write data in a form that is both compact and easy to convert to binary.
The hexadecimal number system, often called hex, is a base-16 system. This means it uses 16 unique symbols to represent numbers. These symbols are:
| Hex Digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Decimal Value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Notice that after 9, letters A to F are used to represent decimal values 10 to 15. This is because we need 16 symbols in total for base 16.
Just like the decimal system, where each digit's place value is a power of 10, in hexadecimal each digit's place value is a power of 16. The rightmost digit is multiplied by \(16^0 = 1\), the next digit to the left by \(16^1 = 16\), then \(16^2 = 256\), and so on.
For example, the hexadecimal number 3F2 represents:
\[3 \times 16^2 + F \times 16^1 + 2 \times 16^0\]Since \(F = 15\) in decimal, this is:
\[3 \times 256 + 15 \times 16 + 2 \times 1 = 768 + 240 + 2 = 1010\]Converting between hexadecimal and decimal is essential to understand and work with hex numbers effectively.
To convert a hexadecimal number to decimal, expand it using place values and sum the results. The general formula is:
To convert a decimal number to hexadecimal, use the repeated division and remainder method:
graph TD A[Start] --> B{Conversion Type?} B -->|Hex to Decimal| C[Expand digits using place values] C --> D[Calculate sum] D --> E[Decimal Result] B -->|Decimal to Hex| F[Divide decimal by 16] F --> G[Record remainder] G --> H{Quotient zero?} H -->|No| F H -->|Yes| I[Read remainders bottom to top] I --> J[Hexadecimal Result]Since computers operate in binary (base 2), converting between hexadecimal and binary is straightforward. Each hex digit corresponds exactly to 4 binary bits (because \(2^4 = 16\)). Similarly, octal (base 8) can be linked to binary by grouping bits in sets of 3.
| Hex | Binary (4 bits) | Octal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 10 |
| 9 | 1001 | 11 |
| A | 1010 | 12 |
| B | 1011 | 13 |
| C | 1100 | 14 |
| D | 1101 | 15 |
| E | 1110 | 16 |
| F | 1111 | 17 |
How to convert:
Arithmetic in hexadecimal follows the same principles as in decimal, but with base 16. This means carry and borrow happen when sums or differences cross 15 (decimal 15).
To add two hex digits, convert them to decimal, add them, then convert back to hex. If the sum is 16 or more, carry 1 to the next higher digit.
Subtract hex digits by converting to decimal. If the minuend digit is smaller than the subtrahend digit, borrow 1 (which equals 16 in decimal) from the next higher digit.
Multiplication and division are performed similarly by converting hex digits to decimal, performing the operation, and converting the result back to hex. For multi-digit numbers, use long multiplication or division methods adapted to base 16.
Step 1: Identify the digits and their decimal values.
2 = 2, F = 15
Step 2: Use place value expansion:
\(2 \times 16^1 + 15 \times 16^0 = 2 \times 16 + 15 \times 1 = 32 + 15 = 47\)
Answer: The decimal equivalent of hex 2F is 47.
Step 1: Convert each digit to decimal.
A = 10, 3 = 3; 1 = 1, C = 12
Step 2: Add the rightmost digits: 3 + 12 = 15 (which is F in hex). No carry since 15 < 16.
Step 3: Add the left digits plus carry: 10 + 1 + 0 = 11 (which is B in hex).
Step 4: Combine the results: left digit B and right digit F.
Answer: A3 + 1C = BF in hexadecimal.
Step 1: Divide 255 by 16:
255 / 16 = 15 remainder 15
Step 2: Divide quotient 15 by 16:
15 / 16 = 0 remainder 15
Step 3: Write remainders from bottom to top: 15 (F), 15 (F)
Answer: Decimal 255 = Hexadecimal FF.
Step 1: Convert hex digits to decimal.
1A = \(1 \times 16 + 10 = 26\), 3 = 3
Step 2: Multiply decimal values: 26 x 3 = 78
Step 3: Convert 78 back to hexadecimal using division:
78 / 16 = 4 remainder 14
4 / 16 = 0 remainder 4
Remainders from bottom to top: 4 (4), 14 (E)
Answer: 1A x 3 = 4E in hexadecimal.
Step 1: Convert each hex digit to 4-bit binary:
7 = 0111, B = 1011
So, 7B in binary is 01111011.
Step 2: Group binary digits in sets of 3 for octal (from right):
0 111 101 1 -> Add leading zero to make full groups: 000 111 101 011
Groups: 000, 111, 101, 011
Step 3: Convert each group to octal digit:
000 = 0, 111 = 7, 101 = 5, 011 = 3
Answer: Hex 7B = Binary 01111011 and Octal 0753.
When to use: Essential for quick conversions and arithmetic in hexadecimal.
When to use: When converting numbers between binary and hex.
When to use: For converting large decimal numbers to hexadecimal efficiently.
When to use: During hexadecimal addition problems to avoid errors.
When to use: When converting any hexadecimal number to decimal for accuracy.
Progress tracking is paywalled — subscribe to mark subtopics as understood and save your streak.
Go to practice →