Hexadecimal Number System

1he Hexadecimal Number Base System

A big problem with the binary system is ·erbosity. 1o represent the ·alue 202 requires eight binary
digits.
1he decimal ·ersion requires only three decimal digits and, thus, represents numbers much more
compactly than does the binary numbering system. 1his íact was not lost on the engineers who
designed binary computer systems.
\hen dealing with large ·alues, binary numbers quickly become too unwieldy. 1he hexadecimal
,base 16, numbering system sol·es these problems. lexadecimal numbers oííer the two íeatures:
hex numbers are ·ery compact
it is easy to con·ert írom hex to binary and binary to hex.
Since we'll oíten need to enter hexadecimal numbers into the computer system, we'll need a diííerent
mechanism íor representing hexadecimal numbers since you cannot enter a subscript to denote the
radix oí the associated ·alue.

1he lexadecimal system is based on the binary system using a Nibble or 4-bit boundary. In
Assembly Language programming, most assemblers require the íirst digit oí a hexadecimal number
to be 0, and we place an l at the end oí the number to denote the number base.

1he lexadecimal Number System:
uses base 16
includes only the digits 0 through 9 and the letters A, B, C, D, L, and l

In the lexadecimal number system, the hex ·alues greater than 9 carry the íollowing decimal ·alue:
Binary Octal Decimal lex
0000B 00Q 00 00l
0001B 01Q 01 01l
0010B 02Q 02 02l
0011B 03Q 03 03l
0100B 04Q 04 04l
0101B 05Q 05 05l
0110B 06Q 06 06l
0111B 0¯Q 0¯ 0¯l
1000B 10Q 08 08l
1001B 11Q 09 09l
1010B 12Q 10 0Al
1011B 13Q 11 0Bl
1100B 14Q 12 0Cl
1101B 15Q 13 0Dl
1110B 16Q 14 0Ll
1111B 1¯Q 15 0ll
10000B 20Q 16 10l


1his table pro·ides all the iníormation you'll e·er need to con·ert írom one number base into any
other number base íor the decimal ·alues írom 0 to 16.

1o con·ert a hexadecimal number into a binary number, simply brake the binary number into 4-bit
groups beginning with the LSB and substitute the corresponding íour bits in binary íor each
hexadecimal digit in the number.

lor example, to con·ert 0ABCDh into a binary ·alue, simply con·ert each hexadecimal digit
according to the table abo·e. 1he binary equi·alent is:

0ABCDl ~ 0000 1010 1011 1100 1101

1o con·ert a binary number into hexadecimal íormat is almost as easy. 1he íirst step is to pad the
binary number with leading zeros to make sure that the the binary number contains multiples oí
íour bits. lor example, gi·en the binary number 10 1100 1010, the íirst step would be to add two
bits in the MSB position so that it contains 12 bits. 1he re·ised binary ·alue is 0010 1100 1010.

1he next step is to separate the binary ·alue into groups oí íour bits, e.g., 0010 1100 1010. linally,
look up these binary ·alues in the table abo·e and substitute the appropriate hexadecimal digits, e.g.,
2CA.

1he weighted ·alues íor each position is as íollows:
16`3 16`2 16`1 16`0
4096 256 16 1

Binary to Hex Conversion

It is easy to con·ert írom an integer binary number to hex. 1his is accomplished by:
Break the binary number into 4-bit sections írom the LSB to the MSB.
Con·ert the 4-bit binary number to its lex equi·alent.


lor example, the binary ·alue 1010111110110010 will be written:
1010 1111 1011 0010
A l B 2

Hex to Binary Conversion

It is also easy to con·ert írom an integer hex number to binary. 1his is accomplished by:
Con·ert the lex number to its 4-bit binary equi·alent.
Combine the 4-bit sections by remo·ing the spaces.

lor example, the hex ·alue 0AlB2 will be written:
A l B 2
1010 1111 1011 0010


1his yields the binary number 1010111110110010 or 1010 1111 1011 0010 in our more readable
íormat.
lex to Decimal Con·ersion

1o con·ert írom lex to Decimal, multiply the ·alue in each position by its hex weight and add each
·alue. Using the ·alue írom the pre·ious example, 0AlB2l, we would expect to obtain the decimal
·alue 449¯8.
A16`3 l16`2 B16`1 216`0
104096 15256 1116 21
40960 3840 1¯6 2

40960 - 3840 - 1¯6 - 2 ~ 449¯8


ecimal to Hex Conversion

1o con·ert decimal to hex is slightly more diííicult. 1he typical method to con·ert írom decimal to
hex is repeated di·ision by 16. \hile we may also use repeated subtraction by the weighted position
·alue, it is more diííicult íor large decimal numbers.
Repeated Di·ision By 16

lor this method, di·ide the decimal number by 16, and write the remainder on the side as the least
signiíicant digit. 1his process is continued by di·iding the quotient by 16 and writing the remainder
until the quotient is 0. \hen períorming the di·ision, the remainders which will represent the hex
equi·alent oí the decimal number are written beginning at the least signiíicant digit ,right, and each
new digit is written to the next more signiíicant digit ,the leít, oí the pre·ious digit. Consider the
number 449¯8.

Di·ision Quotient Remainder lex Number
449¯8 , 16 2811 2 2
2811 , 16 1¯5 11 B2
1¯5 , 16 10 15 lB2
10 , 16 0 0 10 AlB2


As you can see, we are back with the original number. 1hat is what we should expect.

\hen you use hex numbers in an 8085 program, the Assembler usually requires the most signiíicant
hex digit to be 0 e·en ií this number oí digits exceed the size oí the register. 1his is an Assembler
requirement and your ·alue will be assembled correctly.










Hexadecimal numeral system
lrom \ikipedia, the íree encyclopedia
1he hexadecimal numeral system, also known as just hex, is a numeral system made up oí 16
symbols ,base 16,. It uses the common symbols in the decimal numeral system ,0 through 9, and
includes six extra symbols. 1hese symbols are characters taken írom the Lnglish alphabet: A, B, C,
D, L and l. 1he hexadecimal system replaced the octal numeral system íor much oí the work done
on computers. 1he most commonly used íorm oí binary is the byte. 1his is eight binary digits ,bits,.
lexadecimal only needs two digits to show the iníormation in one byte oí data. As computers
become more ad·anced, they tend to use larger groups oí bits but they use multiples oí 8 ,16, 24, 32,
64, etc,. lexadecimal makes it easier to write these large binary numbers. lexadecimal numbers are
written with a "h" aíter the number. lor example, 63h means 63 hexadecimal.
lexadecimal ·alues
lexadecimal is similar to the octal numeral system ,base 8, because each can be easily compared to
the binary numeral system. lexadecimal uses a íour-bit binary coding. 1his means that eachdigit in
hexadecimal is the same as íour digits in binary. Octal uses a three-bit binary system.

Hex Binary Octal ecimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
Hex Binary Octal ecimal
8 1000 10 8
9 1001 11 9
A 1010 12 10
B 1011 13 11
C 1100 14 12
D 1101 15 13
Hex Binary Octal ecimal
10 1 0000 20 16
11 1 0001 21 1¯
24 10 0100 44 36
5L
101
1110
136 94
100
1 0000
0000
400 256
6 110 6 6
¯ 111 ¯ ¯

L 1110 16 14
l 1111 1¯ 15

5C2
101
1100
0010
2¯02 14¯4
1000
1 0000
0000
0000
10000 4096
lACL
1111
1010
1100
1110
1¯5326 64206

Con·ersion
Binary to hexadecimal
Changing a number írom binary to hex uses a grouping method. 1he binary number is separated
into groups oí íour digits starting írom the right. 1hese groups are then con·erted to hexadecimal
digits as shown in the chart abo·e íor the hexadecimal numbers 0 through l. 1o change írom
hexadecimal, the re·erse is done. 1he hex digits are each changed to binary and the grouping is
usually remo·ed.
Binary Groupings Hex
01100101

0110 0101 65
010010110110

0100 1011 0110 4B6
1101011101011010 1101 0111 0101 1010 D¯5A
Hexadecimal and decimal
1o con·ert a number írom hexadecimal to decimal, do the íollowing:
1, 1ake the least signiíicant hexadecimal digit. 1hat is the digit on the right end. Ií it is 0 thru 9 lea·e
it at that ·alue. Ií it is A or abo·e con·ert it to 10 thru 15. 1his will be the íirst item in a sum.
2, 1ake the second-least signiíicant digit. 1hat is next to the digit on the right end. Do the abo·e but
multiply the ·alue obtained by 16. Add this to the sum.
3, 1ake the third-least signiíicant digit and con·ert is as in 1, abo·e, then multiply it by 16
2
,that is,
16 squared, or 256,. Add it to the sum.
4, Repeat the abo·e íor more places. lor each new place, add one more to the power oí 16. Because
hexadecimal uses extra symbols, it is important to remember the decimal ·alue oí each oí the
symbols: A ~ 10, B ~ 11, C ~ 12, D ~ 13, L ~ 14, and l ~ 15.

Location
6 5 4 3 2 1
Value 10485¯6 ,16
5
, 65536 ,16
4
, 4096 ,16
3
, 256 ,16
2
, 16,16
1
, 1 ,16
0
,
Lxample: 5lh and 3425h to decimal

5lh to decimal
Hex

ecima
l
5lh ~ , 5 x 16 , - , 15 x 1 ,
~ 80 - 15
5lh ~ 95


3425h to decimal
Hex

ecimal
3425h ~ , 3 x 4096 , - , 4 x 256 , - , 2 x 16, - , 5 x 1 ,
~ 12288 - 1024 - 32 - 5
3425h ~ 13349

:083909.894.98./0./0.9438174290$9490$  43.557457..73:2-07.-3.-4..:081470.:039474:584114:7-98 0       3..7.2./.-0.73:2-079498006:.-3.43.0.7.0791742.5489438.07843  980.439.81448 ) ) ) )        3..43.9438-7024.900.99090-3.43.7.2.8 %0178989058945.73:2-07    90178989054:/-094.-3.73:2-07940 %88.33900703:2-0794-3.//94 -98390$548943849...80../9 .:0     -079903              0943.382:950841 14:7-98 470.7.-0 1472..73:2-07 825-7.0790.90-3.339007-3.08:709.7.743.43.73:2-07394 -9 74:58-0333990$.0.../0..43.9  0940.2489.706:.:0 825.3:2-07394.73:2-0790.08   470.  44:59080-3.2.73:2-07     47     34:7247070.42580/- 43..0398           %4.0./90 -3../0.38-98 %070.250 90-3.7 %88.2.0791742..3/8:-899:9090.71470./30748942.0390-3.39085.706:.894..-0.:08       %03098905894805.1472..840.794043../93903:2-07   470.99.079 394.039  42-3090 -980..-4.090-3.%4.43.73:2-07394 -980.3/8:-899:9090.07990 -9-3.250 900.47/394909.43./98 0      %0090/.439..7.42580/- 70.47708543/314:7-983-3.250 .079.73:2-073940.2.0 %0-3. 0.80/-3./0.07843  98.0799003:2-079498 -9-3.250 94.9090-3.2.07843  ..039    470.:0 -079903               %80/890-3.079.

84:807050..2.3/07 :39906:490398 035071472390/.89 831.0888.8900./090/0.943-90090/548943 .0394190/0.2.43.94043.//0. 30/987990394903092470831.9944-9..3/078. .:030.4:8/9 438/0790 3:2-07   ..079/0.94 087050..2094/94.2.90/8:-97.548943-98009..4:80...843 ":49039#02.%4.43..843  47982094/ /.2.2.9900..4393:0/-/.89831.3/0.:9147.250   04:/050. .39/9 %8574.:0   )  )  ) )                           0..3:2-078  #050.07917420940.0791742/0.3:2-07.70/0.705708039900 06:...2.3/0743908/0.843- 002.2..:0174290570.90/.3/.:9 %095.3/79390702.843 90702.:0 982470/11.90//.2.390/0..07843  %4.43.39/9 90019 4190570.3:2-07- .:0 &8390. 2:9590.39/9 79 ./3906:49039-.7079903-0333.3/79090702.3/07 0:2-07 .9408892470/11..

    .

    .

      .

9            .3800 0...3/4:7.3 5747.706:708902489831.98.9   034::8003:2-0783.4770.39 0/994-0 0.      84:...70-.00/90804190708907 %88.38802-07 706:702039.990473.9084:/050.3:2-07 %.031983:2-0741/980.2 908802-07:8:.:0-0.8802-0/.

82-48 %08082-48.70.3:207.88902 .3.90. 0././0. 8.2.250 20.794904.70/94 90-3.43300/894/9894849031472.:/088097.9. 0..450/.:800.88902 74250/./0.:808.3:207.2.9. 0.7890-90 %8809-3.2.80 9:80890.2.88902 0.5.9433430-9041/.8.8908...425./0.7  ./0:541 82-48 -.425:9078 -0.2.2.4202470. 90170003.7./0.88902 974: .9.0/904..2./0.2.7/98 -98  0.84343.8:890 8.9.2.882..0890./0.4/3 %820.4224382-48390/0..3:2-078. 0 3./0.9.70 799039. %00. 0.2.788902   0 3.20..889021472:.9.7 .90789..2.807947909080.0317429038.3:207.2.2.380.9.2.0.2.3-00./0.425:9078 %02489.9700 -9-3..814:7/983-3.3:207..-09     .73:207.3:207.:808./0.7 .14:7 -9-3.70774:5841-98-:990:802:950841      09. 0 3.88902 -.3/ %00.  0.42243:80/147241-3.80 -0..7.0/ 90903/94:80.1907903:2-07 470.7 ./0.73:2-078 0.88902705.889022.389.                                                                                               .:08 0../0..3:207.70-3.3/ 3.2./93 0.419047/430 43.

-4.8:2  .7940:808.3:2-078 974: %4..3//0.43..2.9890/943907903/ 198 97:0.94/0.0790/940.079994 97: %8-09017899023.07843 3.30/94-3.079.33. ./0.3/9074:538 :8:./0.7 74:538 0                                        0.700.301742 0.2. /98.0.3:2-0717420.390.9. 9070.2.07808/430 %00/98.3:2-071742-3.2.0 9.90/ 39474:584114:7/9889.70903..7.79.-4.2./0..43./0.7./0./9 %.8843390..79317429079 %08074:58.2./0.2...99. %4.7024.:0 19847. /4901443  %..                                                     43.7940..2.0/  3.0900.73:2-078805.2.74:532094/ %0-3.0147900.89831./0.43.

2.39/9 %..0 9032:959- 9.43.250.83 .08 470.399470202-0790/0.983099490/943907903/ 490.                                 .:808097..//43024709490540741 0.2..990../0. 0                         94/0. 94/0.943        '.0798.43/ 0.39/9.:0                  .98  86:.4190 82-48     .70/ 47 //994908:2   #050.2.3/  4.-4..2.89831.:80 0.-4.2.014724705.3/.-4..3/94/0..09097/ 0.0 .:0410.30/- //9894908:2   %. 0 0.305..0-:9 2:9590.82-48 9825479..:04-9.09080.2...89831.2. %. 0.