Data Representation
Beta Draft  Do not distribute
© 2001, By Randall Hyde
Page
53
Data Representation
Chapter Three
A major stumbling block man
y be
ginners encounter when attempting to learn assembly language is the
common use of the
binary and
he
xadecimal numbering systems. Man
y programmers think that he
xadecimal
(or he
x
1
) numbers represent absolute proof that God ne
v
er intended an
yone to w
ork in assembly language.
While it is true that he
xadecimal numbers are a little dif
ferent from what you may be used to, their adv
an

tages outweigh their disadv
antages by a lar
ge mar
gin. Ne
v
ertheless, understanding these numbering systems
is important because their use simplifi
es other comple
x topics including boolean algebra and logic design,
signed numeric representation, character codes, and pack
ed data.
3.1
Chapter Overview
This chapter discusses se
v
eral important concepts including the binary and he
xadecimal numbering sys

tems, binary data or
g
anization (bits, nibbles, bytes, w
ords, and double w
ords), signed and unsigned number

ing systems, arithmetic, logical, shift, and rotate operations on binary v
alues, bit fi
elds and pack
ed data.
This
is basic material and the remainder of this te
xt depends upon your understanding of these concepts. If you
are already f
amiliar with these terms from other courses or study
, you should at least skim this material
before proceeding to the ne
xt chapter
. If you are unf
amiliar with this material, or only v
aguely f
amiliar with
it, you should study it carefully before proceeding.
All of the material in this c
hapter is important!
Do not
skip o
v
er an
y material.
In addition to the basic material, this chapter also introduces some ne
w HLA state

ments and HLA Standard Library routines.
3.2
Numbering Systems
Most modern computer systems do not represent numeric v
alues using the decimal system. Instead, the
y
typically use a binary or tw
o’
s complement numbering system.
T
o understand the limitations of computer
arithmetic, you must understand ho
w computers represent numbers.
3.2.1
A Review of the Decimal System
Y
ou’
v
e been using the
decimal (base 10) numbering system for so long that you probably tak
e it for
granted.
When you see a number lik
e “123”, you don’
t think about the v
alue 123; rather
, you generate a
mental image of ho
w man
y items this v
alue represents. In reality
, ho
we
v
er
, the number 123 represents:
1*10
2
+ 2 * 10
1
+ 3*10
0
or
100+20+3
In the positional numbering system, each digit appearing to the left of the decimal point represents a
v
alue between zero and nine times an increasing po
wer of ten. Digits appearing to the right of the decimal
point represent a v
alue between zero and nine times an increasing ne
g
ati
v
e po
wer of ten. F
or e
xample, the
v
alue 123.456 means:
2
+ 2*10
1
0
+ 4*10
1
+ 5*10
2
+ 6*10
3
or
100 + 20 + 3 + 0.4 + 0.05 + 0.006
1. Hexadecimal is often abbreviated as
hex
even though, technically speaking, hex means base six, not base sixteen.