Comparing the hexadecimal number system to the decimal number system
In the decimal number system a digit can have any value between 0 and 9 inclusive. In the hexadecimal number system a digit can only have the value 0 or 15. This is a bit strange since we run out of numerical digits once we get to 9. We overcome this in the hexadecimal number system a digit by use A for digit 10, B for digit 11, C for digit 12, D for digit 13, E for digit 14 and F for digit 15So the number 41F6 is a valid hexadecimal number and an invalid decimal number. The number 4156 is a valid hexadecimal number and a valid decimal number, but hexadecimal 4156 is not the same value as decimal 4156.
If there is any ambiguity as to which number system (also somtimes refered to as base or radix) we are using, then we should prefix the number with either the word hexadecimal or decimal or subscript it with 16 or 10 e.g. 415616 for hexadecimal 4156 or 415610 for decimal 4156
As previously explained, in the decimal number system each digit has 10 times the magnitude of the digit on its right. That is, the thousands digit is 10 times greater than the hundreds digit which is 10 times greater than the tens digit which is 10 times greater than the units
In contrast in the hexadecimal number system each digit has 16 times the magnitude of the digit on its right. So whereas we have thousands, hundreds, tens and units in the deciaml number system, we have 64K's, 4K's, two hundred and fifty sixes, sixteens and units in the hexadecimal number system.
DECIMAL HEXADECIMAL units x 1 units x 1 tens x 10 sixteens x 16 hundreds x 10 x 10 two hundred and fifty sixes x 16 x 16 thousands x 10 x 10 x 10 4K's x 16 x 16 x 16 ten thousands x 10 x 10 x 10 x 10 64K's x 16 x 16 x 16 x 16 As previously explained, in maths there is a special notation for multiplying a number by itself many times, and the process is refered to as raising the number to a power.
e.g.
16 x 16 is the same as saying 16 to the power of 2, this is written as 162
16 x 16 x 16 is the same as saying 16 to the power of 3, this is written as 163
16 x 16 x 16 x 16 is the same as saying 16 to the power of 4, this is written as 164
16 on its own is the same as saying 16 to the power of 1, this is written as 161
In general the power that 16 is raised to is the number of 16's to be multiplied together, so 16N is N 16's multiplied together.
We can re-write the above hexadecimal table as:
NOTE: N0 is always 1 (take this on trust it's a maths thing) so the above table is completed as
units x 1 sixteens x 16 161 two hundred and fifty sixes x 16 x 16 162 4K's x 16 x 16 x 16 163 64K's x 16 x 16 x 16 x 16 164 Again comparing the decimal and hexadecimal table but this time with emphesis on the powers of 10 and 16 for each digit
units x 1 160 sixteens x 16 161 two hundred and fifty sixes x 16 x 16 162 4K's x 16 x 16 x 16 163 64K's x 16 x 16 x 16 x 16 164 With decimal numbers when we append a 0 to a number we effectively multiply it by 10.
DECIMAL HEXADECIMAL units 100 units 160 tens 101 sixteens 161 hundreds 102 two hundred and fifty sixes 162 thousands 103 4K's 163 ten thousands 104 64K's 164 e.g.With hexadecimal numbers when we append a 0 to a number we effectively multiply it by 16.4156
append 0 becomes
41560e.g.With decimal numbers when we trim off the units digit we effectively divide it by 10.3116 (which is equivalent to 4910)
append 0 becomes
31016 (which is equivalent to 78410)e.g.With hexadecimal numbers when we trim off the units digit we effectively divide it by 16.4156
trim off 6 becomes
415e.g.3116 (which is equivalent to 4910)
trim off 1 becomes
316 (which is equivalent to 310)In general, if we append N 0's to a decimal number we effectively multiply it by 10N. If we append N 0's to a hexadecimal number we effectively multiply it by 16N. If we trim the N least significand digits from a decimal number we effectively divide it by 10N. If we trim the N least significand digits from a hexadecimal number we effectively divide it by 16N.
Why bother with hexadecimal numbers
Because each hexadecimal digit translates to execatly 4 binary digits and this simplifies handling binary numbers and masks.
binary 27 26 25 24 23 22 21 20 hexadecimal 161 160 So the binary number 10010110 translates to hexadecimal number 96
binary hexadecimal 23 22 21 20 160 0 0 0 0 0 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 1 0 0 1 9 1 0 1 0 A 1 0 1 1 B 1 1 0 0 C 1 1 0 1 D 1 1 1 0 E 1 1 1 1 F So the binary number 1110001110100101 translates to hexadecimal number E3A5
binary 27 26 25 24 23 22 21 20 1 0 0 1 0 1 1 0 hexadecimal 161 160 9 6
binary 215 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20 1 1 1 0 0 0 1 1 1 0 1 0 0 1 0 1 hexadecimal 163 162 161 160 E 3 A 5