Vous êtes sur la page 1sur 6

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 soles these problems. lexadecimal numbers oer the two eatures:
hex numbers are ery compact
it is easy to conert rom hex to binary and binary to hex.
Since we'll oten need to enter hexadecimal numbers into the computer system, we'll need a dierent
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 0Q 0 0l
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 1Q 15 0ll
10000B 20Q 16 10l


1his table proides all the inormation you'll eer need to conert rom one number base into any
other number base or the decimal alues rom 0 to 16.

1o conert 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 conert 0ABCDh into a binary alue, simply conert each hexadecimal digit
according to the table aboe. 1he binary equialent is:

0ABCDl ~ 0000 1010 1011 1100 1101

1o conert 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, gien 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 reised 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 aboe 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 conert 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.
Conert the 4-bit binary number to its lex equialent.


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 conert rom an integer hex number to binary. 1his is accomplished by:
Conert the lex number to its 4-bit binary equialent.
Combine the 4-bit sections by remoing 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 Conersion

1o conert rom lex to Decimal, multiply the alue in each position by its hex weight and add each
alue. Using the alue rom the preious example, 0AlB2l, we would expect to obtain the decimal
alue 4498.
A16`3 l16`2 B16`1 216`0
104096 15256 1116 21
40960 3840 16 2

40960 - 3840 - 16 - 2 ~ 4498


ecimal to Hex Conversion

1o conert decimal to hex is slightly more diicult. 1he typical method to conert rom decimal to
hex is repeated diision by 16. \hile we may also use repeated subtraction by the weighted position
alue, it is more diicult or large decimal numbers.
Repeated Diision By 16

lor this method, diide the decimal number by 16, and write the remainder on the side as the least
signiicant digit. 1his process is continued by diiding the quotient by 16 and writing the remainder
until the quotient is 0. \hen perorming the diision, the remainders which will represent the hex
equialent o the decimal number are written beginning at the least signiicant digit ,right, and each
new digit is written to the next more signiicant digit ,the let, o the preious digit. Consider the
number 4498.

Diision Quotient Remainder lex Number
4498 , 16 2811 2 2
2811 , 16 15 11 B2
15 , 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 signiicant
hex digit to be 0 een 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 inormation in one byte o data. As computers
become more adanced, 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" ater 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
202 144
1000
1 0000
0000
0000
10000 4096
lACL
1111
1010
1100
1110
15326 64206

Conersion
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 conerted to hexadecimal
digits as shown in the chart aboe or the hexadecimal numbers 0 through l. 1o change rom
hexadecimal, the reerse is done. 1he hex digits are each changed to binary and the grouping is
usually remoed.
Binary Groupings Hex
01100101

0110 0101 65
010010110110

0100 1011 0110 4B6
1101011101011010 1101 0111 0101 1010 D5A
Hexadecimal and decimal
1o conert a number rom hexadecimal to decimal, do the ollowing:
1, 1ake the least signiicant hexadecimal digit. 1hat is the digit on the right end. I it is 0 thru 9 leae
it at that alue. I it is A or aboe conert it to 10 thru 15. 1his will be the irst item in a sum.
2, 1ake the second-least signiicant digit. 1hat is next to the digit on the right end. Do the aboe but
multiply the alue obtained by 16. Add this to the sum.
3, 1ake the third-least signiicant digit and conert is as in 1, aboe, then multiply it by 16
2
,that is,
16 squared, or 256,. Add it to the sum.
4, Repeat the aboe 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 104856 ,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

Vous aimerez peut-être aussi