What is hexadecimal?
This is a common syntax for describing numbers with computers. It’s basically what we call “base 16” versus binary which is base 2 and decimal which is base 10.
Most human usually use base 10 - decimal for day to day usage.
We have 16 digits in hexadecimal - 0, 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
F would be 15 in decimal.
The second column in hexadecimal means the number of 16’s - just.
Why do programmers like hexadecimal (or hex for short).
It maps more easily to binary than decimal numbers.
Think of port numbers which are represented in 16 bits. 4 bits which are either 1 or 0 can be represented in hex as one digit. See it in this table:
Decimal | Binary | Hex |
---|---|---|
1 | 1 | 1 |
2 | 10 | 2 |
3 | 11 | 3 |
4 | 100 | 4 |
5 | 101 | 5 |
6 | 110 | 6 |
7 | 111 | 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 |
16 | 10000 | 10 |
Hexadecimal is great in software because is nice compromise as format that is easier for humans to read but also maps better to binary because as we can see from the chart the roll over happens at the same time for binary and hex - but for decimal it doesn’t line up nicely.
For instance translate this hex number 0xFFFF into binary - it’s will be:
1111 1111 1111 1111
but in decimal I would need to do:
15 + 15 * 16 + (15 * 16 * 16) + 15 * 16^3