If you've ever wondered about those mysterious numbers that start with "0x" in programming or seen color codes like "#FF5733" in web design, you're looking at hexadecimal numbers! Let's dive into what hex numbers are and how to work with them.
Hexadecimal (or "hex" for short) is a base-16 number system. While we normally use base-10 (decimal) with digits 0-9, hex uses 16 different symbols:
Here's what each hex digit represents in decimal:
Converting from hex to decimal involves understanding positional values. Just like in decimal where each position represents powers of 10, in hex each position represents powers of 16.
For a hex number, multiply each digit by its corresponding power of 16 and add them up:
Let's convert the hex number 3F2 to decimal:
Identify each digit and its position:
Convert hex digits to decimal:
Apply the formula:
Add them up:
So 3F2 (hex) = 1010 (decimal)!
Converting decimal to hex involves repeatedly dividing by 16 and keeping track of remainders.
Divide 255 by 16:
Divide the quotient (15) by 16:
Read the remainders from bottom to top:
So 255 (decimal) = FF (hex)!
Adding hex numbers works similarly to decimal addition, but you carry over when the sum exceeds 15 (F).
A3
+ 2F
----
Add the rightmost digits:
Add the next column with carry:
Result: A3 + 2F = D2
Subtraction in hex follows the same borrowing rules as decimal, but you borrow 16 instead of 10.
B4
- 27
----
Subtract the rightmost digits:
Subtract the next column (remember we borrowed):
Result: B4 - 27 = 8D
Hex multiplication can be done by converting to decimal, multiplying, then converting back, or by using the traditional multiplication method with hex arithmetic.
Using the direct method:
Result: 2A × 3 = 7E
Division in hex is typically done by converting to decimal, dividing, then converting the result back to hex.
Convert C8 to decimal:
Divide in decimal:
Convert 50 back to hex:
So C8 ÷ 4 = 32 (hex)
Hex numbers are everywhere in technology:
Decimal | Binary | Hex |
---|---|---|
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 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |