Understanding Binary: Hexadecimal
Topically, hexadecimal is extremely useful for programmers to understand, and makes binary in general quite a bit easier to work with and represent both in code and out.
The Hexadecimal System (base 16)
Binary numbers range from 0 to 1, decimal numbers range from 0-9, and hexadecimal numbers range from 0-15. To keep it relatively easy to read, and more succinct than writing 10, 11, 12... out the numbers over 9 are remapped to the characters A, B, C...
This allows a single "digit" to be represented by a single "character" in writing.
|base 10||base 16||base 10||base 16|
It is customary to write hexadecimal numbers as 0x(hexadecimal), e.g. 0xF9, or 0x23A2.
Justification for Hexadecimal
Now that you know what a hexadecimal number is, and how to recognize them... Why would we bother with a completely new numbering scheme?
Remember how ugly it became working with relatively large binary numbers, say over 100 (7 binary digits)? Remember when I said it was customary to keep long binary numbers clumped up into 4 digit chunks??
That is because every 4 digit binary number corresponds perfectly with one of these new fangled hexadecimal numbers.
|base 2||base 16||base 2||base 16|
This is great because we can take LONGGG strings of binary and quickly convert them into a much easier to read, write, and say form.
Convert 1010 1101 0011 1001b into hexadecimal
This is actually very easy, we first lookup 1010b from our chart: 0xA
1101b = 0xD
0011b = 0x3
1001b = 0x9
Put them all together and you get the answer: 0xAD39
Convert 0x2F into binary
Easy enough, right?
"I though computers only understood binary?"
That is true. But humans and computers are much better faster at converting hexadecimal numbers into their binary equivalents. For this reason hexadecimal is a convenient way of entering constant numbers in code.