## 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.

4156for hexadecimal 4156 or_{16}4156for decimal 4156_{10}As previously explained, in the decimal number system each digit has

10times the magnitude of the digit on its right. That is, thethousandsdigit is10times greater than thehundredsdigit which is10times greater than thetensdigit which is10times greater than theunitsIn contrast in the hexadecimal number system each digit has

16times the magnitude of the digit on its right. So whereas we havethousands,hundreds,tensandunitsin the deciaml number system, we have64K's,4K's,two hundred and fifty sixes,sixteensandunitsin the hexadecimal number system.

DECIMALHEXADECIMALunitsx 1unitsx 1tensx 10sixteensx 16hundredsx 10 x 10two hundred and fifty sixesx 16 x 16thousandsx 10 x 10 x 104K'sx 16 x 16 x 16ten thousandsx 10 x 10 x 10 x 1064K'sx 16 x 16 x 16 x 16As 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 16is the same as saying16to the power of2, this is written as16^{2}

16 x 16 x 16is the same as saying16to the power of3, this is written as16^{3}

16 x 16 x 16 x 16is the same as saying16to the power of4, this is written as16^{4}

16on its own is the same as saying16to the power of1, this is written as16^{1}

In general the power that

16is raised to is the number of16's to be multiplied together, so16is^{N}N 16's multiplied together.We can re-write the above hexadecimal table as:

unitsx 1sixteensx 1616^{1}two hundred and fifty sixesx 16 x 1616^{2}4K'sx 16 x 16 x 1616^{3}64K'sx 16 x 16 x 16 x 1616^{4}NOTE:Nis always^{0}1(take this on trust it's a maths thing) so the above table is completed asAgain comparing the decimal and hexadecimal table but this time with emphesis on the powers of 10 and 16 for each digit

unitsx 116^{0}sixteensx 1616^{1}two hundred and fifty sixesx 16 x 1616^{2}4K'sx 16 x 16 x 1616^{3}64K'sx 16 x 16 x 16 x 1616^{4}With decimal numbers when we append a

DECIMALHEXADECIMALunits10^{0}units16^{0}tens10^{1}sixteens16^{1}hundreds10^{2}two hundred and fifty sixes16^{2}thousands10^{3}4K's16^{3}ten thousands10^{4}64K's16^{4}0to a number we effectively multiply it by10.e.g.With hexadecimal numbers when we append a4156

append0becomes

415600to a number we effectively multiply it by16.e.g.With decimal numbers when we trim off the units digit we effectively divide it by31(which is equivalent to_{16}49)_{10}

append0becomes

310(which is equivalent to_{16}784)_{10}10.e.g.With hexadecimal numbers when we trim off the units digit we effectively divide it by4156

trim off6becomes

41516.e.g.31(which is equivalent to_{16}49)_{10}

trim off1becomes

3(which is equivalent to_{16}3)_{10}In general, if we append

N 0's to a decimal number we effectively multiply it by10. If we append^{N}N 0's to a hexadecimal number we effectively multiply it by16. If we trim the^{N}Nleast significand digits from a decimal number we effectively divide it by10. If we trim the^{N}Nleast significand digits from a hexadecimal number we effectively divide it by16.^{N}## Why bother with hexadecimal numbers

Because each hexadecimal digit translates to execatly 4 binary digits and this simplifies handling binary numbers and masks.

binary 2^{7}2^{6}2^{5}2^{4}2^{3}2^{2}2^{1}2^{0}hexadecimal 16^{1}16^{0}So the binary number 10010110 translates to hexadecimal number 96

binary hexadecimal 2^{3}2^{2}2^{1}2^{0}16^{0}000000001100102001130100401015011060111710008100191010A1011B1100C1101D1110E1111FSo the binary number 1110001110100101 translates to hexadecimal number E3A5

binary 2^{7}2^{6}2^{5}2^{4}2^{3}2^{2}2^{1}2^{0}10010110hexadecimal 16^{1}16^{0}96

binary 2^{15}2^{14}2^{13}2^{12}2^{11}2^{10}2^{9}2^{8}2^{7}2^{6}2^{5}2^{4}2^{3}2^{2}2^{1}2^{0}1110001110100101hexadecimal 16^{3}16^{2}16^{1}16^{0}E3A5