


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















z^ Integer
Representation z^ Floating
‐point Representation z^ Other
data^ types
z^ Base
10 Number
Representation
-^ Natural
representation
for^ human
transactions
H^ d^
I^ l^
El^
i^ ll^
z^ H
ard^ to
Implement
Electronically
-^ Hard
to^ store z ENIAC^ (First
electronic
computer)
used^10
vacuum
tubes^ /
digit
-^ Hard
to^ transmitN^ d hi h
i i
t^
d^10
i^ l l^
l^ i^
l^ i
z^ Need
high^ precision
to^ encode
10 signal
levels^ on^ single
wire
-^ Messy
to^ implement
digital
logic^ functions
z^ Addition,
multiplication,
etc.
z^ Binary
RepresentationSpecifically the devices that make up a computer are switches that can be– Specifically,
the^ devices
that^ make
up^ a^ computer
are^ switches
that^ can
be
on^ or^ off,
i.e.^ at
high^ or
low^ voltage.
-^ Easy
to^ store
with^ bistable elements
-^ Reliably
transmitted
on^ noisy
and^ inaccurate
wires
z^ Examples
1
0
1
z^ Examples
-^ Represent
3.5^10
as^ 11.
2
-^ Represent
15213
as^1110110110110110
2
-^ Represent
1.20^10
as^ 1.0011001100110011[0011]…
2
z^ Binary floating point number cannot exactly represent $1 20
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
z^ Binary
floating
point^
number
cannot
exactly
represent
$1.
3-bits
5-bits
8-bits
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
N-^
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
+4^ CEG 320/520Comp. Org. & Assembly
z^ Binary
to^ Decimal
conversion
&^ vice
‐versa
binary
number
A^ =^ a^3
a^ a^ a^210
corresponds
to:
(^3) a x (^23) +^ a^ x^2
2 2 +^ a^1
(^1) x 2 +^
(^0) a x (^20) =^ a^ x^3
8 +^ a^2 x^4 +^ a
x^2 +^1
a^ x^10
(where
a^ =^0 i^
or^1 only)
number
can^ be
broken
down
by^ iteratively
determining
the^ highest
power
of
two^ that
“fits”^
in^ the^
number:
e.g.^ (13)
=> 10 e.g.^ (63)
=> 10 e.g.^ (0.63)
=> 10
2’s^ complement
representation,
leading
zeros^
do^ not affect
the^ value
of^ a^ positive
binary
number,
and^ leading
ones^ do
not affect
the^ value
of^ a^ negative
number.
So:
01101 = 00001101 = 13
and^
11011 = 11111011 = 5
01101
=^00001101
=^13
and^11011
=^11111011
=^ ‐^5
00001101
x0D
11111011
xFB
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
00001000
=>^8 (as
expected!)
x
we^ add
the^ two
(2’s^ complement)
4 bit^
numbers
representing
7 and
5 we
get^ :
(in^4
bit^ 2’s
comp.)
z^ We^ get^ ‐4,
not^ +
as^ we
would
expect
!!
z^ We have
overflowed
the range of 4 bit 2’s comp ( 8 to +7) so the result is invalid
z^ We^ have^ overflowed
the^ range
of^4 bit
2 s^ comp
.^ (‐^8 to
+7),^ so
the^ result
is^ invalid
.
z^ Note
that^ if
we^ add
16 to^
this^ result
we^ get
back^16
‐^4 =^12
like^ “stepping
up”^ to
5 bit^ 2’s
complement
representation
l if h
f^
i i^
b^
d^
i^
l
if^ the
sum^ of^ two
positive
numbers
produces
a^ negative
result,
or
vice^ versa,
an^ overflow
has^ occurred,
and^ the
result
is^ invalid
in^ that
representation. Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
machine
with^
32 bit
word
size,^
two’s
complement
integers
For each of the following C++ expressions either– For^ each
of^ the
following
C++^ expressions
,^ either
z^ Argue
that^ is
true^ for
all^ argument
values
z^ Give
example
where
not^ true
-^ x * x >= 0 •^ ux >= 0 •^ ux
Initialization
ux >
-^ x < 0
⇒^ (2x) < 0*
-^ x > y
⇒^ -x < -y
Initializationint x = foo();int y = bar();
-^ x > 0 && y > 0
x + y > 0
-^ x >= 0
⇒^ -x <= 0
y unsigned ux = x;unsigned uy = y;
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
-^ x^
⇒^ - x
-^ 2.4,
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
z^ Most
numbers
are^ not
integer!
z^ Range:– The
magnitude
of^ the
numbers
we^ can
represent
is^ determined
by^ how
many
bits^ we
use:^ z^ e.g.
with^32
bits^ the
largest
number
we^ can
represent
is^ about
+/‐^2 billion,
far^ too
small^ for
many^ purposes. z^ Precision:– The
exactness
with^ which
we^ can
specify
a^ number:
z^ e.g.^ a
32 bit^ number
gives^ us
31 bits
of^ precision,
or^ roughly
9 figure
precision
in^ decimal
representationrepresentation z^ Our
decimal
system
handles
non‐integer
real^ numbers
by^ adding
yet^ another
symbol
‐^ the decimal
point
(.)^ to make
a^ fixed
point
notation:
3,456.
=^ 3.
3 +^ 5.
2 +^ 4.
1 +^ 6.
0 +^ 7.
‐^1 +^ 8.
‐^2
g^ , z^ The
floating
point
,^ or^ scientific,
notation
allows
us^ to
represent
very^ large^
and
very^ small
numbers
(integer
or^ real),
with^
as^ much
or^ as
little^
precision
as
needed.
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
needed.
Wouldn’t
it^ be^
nice^ if
we^ could
“float”
the^ decimal
Wouldn’t
it^ be^
nice^ if
we^ could
“float”
the^ decimal
f^
f f^
f
point to^ allow
for^ either
case?
point to^ allow
for^ either
case?
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
first^ use
a^ “binary
point”
to^ separate
whole
numbers
from fractional
numbers
to^ make
a^ fixed
point
notation:
z^ e.g. 25.
=^ 1.2 10 4 + 1.
3 + 1.
1 + 1.
‐^1 + 1.
‐^2 = 11001.
2
e.g.^ 25.
1.2 10
2
‐^1 (2=^ 0.
and^2 ‐^2 =^ 0.25,
etc.)
then^ “float”
the^ binary
point:
z^ 00011001.
=>^ 1.
(^4) x 2
mantissa
=^ 1.1001110,
exponent
=^4
we^ have
to^ express
this^ without
the^ extra
symbols
(^ x,^ 2,
p^
y^
z^ by^ convention,
we^ divide
the^ available
bits^ into
three fields:
sign,^ mantissa,
exponent
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
( biased exp.
“normalize”
the^ mantissa
by^ dropping
the^ leading
1 and
recording
only^ its
f^ ti l^
t (^ h ?) fractional
part^ (why?)
to^ handle
both^
+^ and
‐^ exponents,
we^ add
127 to
the^ actual
t t^
t^ “bi
d^
t” (thi
id^
l^
hi^
d^ !)
exponent
to^ create
a^ “biased
exponent”
(this^
provides
a^ lexographic
order!)
‐^127 z 2 =>^ biased
exponent
=^0000
0000
(=^ 0)
(^0) z 2 => biased
exponent
=^0111
1111
(=^ 127)
+127 z 2 => biased exponent = 1111 1110 (= 254)
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
z^2
^ biased
exponent
1111
1110
(^ 254)
(biased exp. – 1023)
+/-^ => approx 10
+/-
+/ 127 2 => approx. 10
+/ 38
mantissa of 52 bits + 1 => approx. 15 digits decimal+/ 1023 2
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly
=> approx. 10
+/-
float
single
precision
double
double
precision
between
int,
float
,^ and^
double
changes
numeric
values
g^
g
-^ Double
or^ float
to^ int
z^ Truncates
fractional
part
z^ Like
rounding
toward
zero
z^ Not
defined
when
out^ of
range
-^ Generally
saturates
to^ TMin
or^ TMax
-^ int
to^ double E^
i^
l^
i^ h^
≤^ 53 bi
d
i
z^ Exact
conversion,
as^ long
as^ int^
has^ ≤^ 53 bit^
word^ size
-^ int
to^ float z Will^ round
according
to^ rounding
mode
Wright State University, College of EngineeringDr. Doom, Computer Science & Engineering
CEG 320/520Comp. Org. & Assembly