Hexadecimal

From Linux 101, The beginner's guide to all things Linux.

Jump to: navigation, search

Hexadecimal, or hex, is a shorthand representation of binary. Although computers do not use it natively, it is often easier on humans to read hexadecimal instead of a much longer chain of binary.

Often times before a hexadecimal number a 0x is placed to indicate it as hexadecimal.

Hex is base 16 in the number system. Because of this, we need 16 symbols to represent the digits. 0 to 9 are obvious candidates, but because that is only 10 symbols, we need an additional 6. We take these from the beginning of the alphabet, so our actual symbol list is 0123456789ABCDEF.


Decimal value Binary value Hexadecimal value
0 0000 0x0
1 0001 0x1
2 0010 0x2
3 0011 0x3
4 0100 0x4
5 0101 0x5
6 0110 0x6
7 0111 0x7
8 1000 0x8
9 1001 0x9
10 1010 0xA
11 1011 0xB
12 1100 0xC
13 1101 0xD
14 1110 0xE
15 1111 0xF

The conversion table above shows how to convert from three important bases to one another. The important thing to note is that each hex digit represents 4 binary digits. This makes conversion between the two extremely easy: break any binary digit into groups of four, then use the table above to convert.

Example #1:
1101 1110 1010 1101 1011 1110 1110 1111 -> 0xDEADBEEF
0xD  0xE  0xA  0xD  0xB  0xE  0xE  0xF
Example #2: 
0xDECAFBAD -> 1101 1110 1100 1010 1111 1110 1010 1101

The above were good examples of how in some instances you can use hex to spell words, but that is rarely the case in terms of computers.

Personal tools