Principles of Computer Architecture: Miles Murdocca and Vincent Heuring
Principles of Computer Architecture: Miles Murdocca and Vincent Heuring
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-2 Chapter 2: Data Representation
Chapter Contents
2.1 Introduction
2.2 Fixed Point Numbers
2.3 Floating Point Numbers
2.4 Case Study: Patriot Missile Defense Failure Caused by Loss of
Precision
2.5 Character Codes
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-3 Chapter 2: Data Representation
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-4 Chapter 2: Data Representation
Example:
541.2510 = 5 102 + 4 101 + 1 100 + 2 10-1 + 5 10-2
= (500)10 + (40)10 + (1)10 + (2/10)10 + (5/100)10
= (541.25)10
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-5 Chapter 2: Data Representation
11/2 = 5 R1
5/2 = 2 R1
2/2 = 1 R0
(23)10 = (10111)2
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-6 Chapter 2: Data Representation
.75 2 = 1.5 0
.5 2 = 1.0 0
Least significant bit
(.375)10 = (.011)2
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-7 Chapter 2: Data Representation
.4 2 = 0.8
.8 2 = 1.6
.6 2 = 1.2
.2 2 = 0.4
.
.
.
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-8 Chapter 2: Data Representation
How many bits should be used for each base 4, 8, etc., digit? For
base 2, in which 2 = 21, the exponent is 1 and so one bit is used
for each base 2 digit. For base 4, in which 4 = 22, the exponent is
2, so so two bits are used for each base 4 digit. Likewise, for base
8 and base 16, 8 = 23 and 16 = 24, and so 3 bits and 4 bits are used
for base 8 and base 16 digits, respectively.
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-10 Chapter 2: Data Representation
Binary Addition
This simple binary addition example provides background for the
signed number representations to follow.
Carry in 0 0 0 0 1 1 1 1
0 0 1 1 0 0 1 1
Operands
+ 0 + 1 + 0 + 1 + 0 + 1 + 0 + 1
0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 1
Example:
Carry Sum
out Carry 1 1 1 1 0 0 0 0
Addend: A 0 1 1 1 1 1 0 0 (124)10
Augend: B + 0 1 0 1 1 0 1 0 (90)10
Sum 1 1 0 1 0 1 1 0 (214)10
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-11 Chapter 2: Data Representation
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-12 Chapter 2: Data Representation
Signed Magnitude
Also know as sign and magnitude, the leftmost bit is the sign (0
= positive, 1 = negative) and the remaining bits are the magnitude.
Example:
+2510 = 000110012
-2510 = 100110012
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-13 Chapter 2: Data Representation
Ones Complement
The leftmost bit is the sign (0 = positive, 1 = negative). Negative of
a number is obtained by subtracting each bit from 2 (essentially,
complementing each bit from 0 to 1 or from 1 to 0). This goes both
ways: converting positive numbers to negative numbers, and con-
verting negative numbers to positive numbers.
Example:
+2510 = 000110012
-2510 = 111001102
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-14 Chapter 2: Data Representation
Twos Complement
The leftmost bit is the sign (0 = positive, 1 = negative). Negative of
a number is obtained by adding 1 to the ones complement nega-
tive. This goes both ways, converting between positive and nega-
tive numbers.
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-15 Chapter 2: Data Representation
Excess (Biased)
The leftmost bit is the sign (usually 1 = positive, 0 = negative).
Positive and negative representations of a number are obtained
by adding a bias to the twos complement representation. This
goes both ways, converting between positive and negative num-
bers. The effect is that numerically smaller numbers have smaller
bit patterns, simplifying comparisons for floating point exponents.
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-18 Chapter 2: Data Representation
+ 2 3 6 . 0 2 3
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-19 Chapter 2: Data Representation
Normalization
The base 10 number 254 can be represented in floating point form
as 254 100, or equivalently as:
25.4 101, or
2.54 102, or
.254 103, or
.0254 104, or
infinitely many other ways, which creates problems when making
comparisons, with so many representations of the same number.
Floating point numbers are usually normalized, in which the radix
point is located in only one possible position for a given number.
Usually, but not always, the normalized representation places the
radix point immediately to the left of the leftmost, nonzero digit in
the fraction, as in: .254 103.
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-20 Chapter 2: Data Representation
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-23 Chapter 2: Data Representation
2 ((M - m) + 1) (b - 1) bs-1 + 1
3 1 1 0 1 1 3
1 1
2 2 2 2
4 4
1 1 b = 2 M = +1
8 8 s = 3 m = 2
Smallest number is 1/8
Largest number is 7/4
Smallest gap is 1/32
Largest gap is 1/4
Number of representable numbers is 33.
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-25 Chapter 2: Data Representation
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-26 Chapter 2: Data Representation
Conversion Example
Example: Convert (9.375 10-2)10 to base 2 scientific notation
Start by converting from base 10 floating point to base 10 fixed
point by moving the decimal point two positions to the left, which
corresponds to the -2 exponent: .09375.
Next, convert from base 10 fixed point to base 2 fixed point:
.09375 2 = 0.1875
.1875 2 = 0.375
.375 2 = 0.75
.75 2 = 1.5
.5 2 = 1.0
Thus, (.09375)10 = (.00011)2.
Finally, convert to normalized base 2 floating point:
.00011 = .00011 20 = 1.1 2-4
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-27 Chapter 2: Data Representation
32 bits
Single
8 bits 23 bits
precision
Exponent Fraction
Sign
(1 bit) 64 bits
Double
precision 11 bits 52 bits
Exponent Fraction
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-28 Chapter 2: Data Representation
IEEE-754 Examples
Value Bit Pattern
Sign Exponent Fraction
(a) +1.101 25 0 1000 0100 101 0000 0000 0000 0000 0000
(b) 1.01011 2126 1 0000 0001 010 1100 0000 0000 0000 0000
(c) +1.0 2127 0 1111 1110 000 0000 0000 0000 0000 0000
(d) +0 0 0000 0000 000 0000 0000 0000 0000 0000
(e) 0 1 0000 0000 000 0000 0000 0000 0000 0000
(f) + 0 1111 1111 000 0000 0000 0000 0000 0000
(g) +2128 0 0000 0000 010 0000 0000 0000 0000 0000
(h) +NaN 0 1111 1111 011 0111 0000 0000 0000 0000
(i) +2128 0 011 0111 1111 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-29 Chapter 2: Data Representation
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-30 Chapter 2: Data Representation
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-31 Chapter 2: Data Representation
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring
2-32 Chapter 2: Data Representation
00 NUL 20 DS 40 SP 60 80 A0 C0 { E0 \
Character 04 PF
05 HT
06 LC
24 BYP 44
25 LF
26 ETB 46
45
64
65
66
84 d
85 e
86 f
A4
A5
A6
u
v
w
C4
C5
C6
D
E
F
E4
E5
E6
U
V
W
Unicode
0003 ETX 0023 # 0043 C 0063 c 0083 Ctrl 00A3 00C3 00E3
0004 EOT 0024 $ 0044 D 0064 d 0084 Ctrl 00A4 00C4 00E4
0005 ENQ 0025 % 0045 E 0065 e 0085 Ctrl 00A5 00C5 00E5
0006 ACK 0026 & 0046 F 0066 f 0086 Ctrl 00A6 00C6 00E6
Code 000B VT
000C FF
000D CR
002B +
002C
002D -
004B
004C
004D
K
L
M
006B k
006C l
006D m
008B Ctrl
008C Ctrl
008D Ctrl
00AB
00AC
00AD
00CB
00CC
00CD
00EB
00EC
00ED
000E SO 002E . 004E N 006E n 008E Ctrl 00AE 00CE 00EE
000F SI 002F / 004F O 006F o 008F Ctrl 00AF 00CF 00EF
0010 DLE 0030 0 0050 P 0070 p 0090 Ctrl 00B0 00D0 D 00F0
0011 DC1 0031 1 0051 Q 0071 q 0091 Ctrl 00B1 00D1 00F1
0012 DC2 0032 2 0052 R 0072 r 0092 Ctrl 00B2 2 00D2 00F2
0013 DC3 0033 3 0053 S 0073 s 0093 Ctrl 00B3 3 00D3 00F3
0014 DC4 0034 4 0054 T 0074 t 0094 Ctrl 00B4 00D4 00F4
0015 NAK 0035 5 0055 U 0075 u 0095 Ctrl 00B5 00D5 00F5
Unicode is a 16- 0016 SYN
0017 ETB
0036 6
0037 7
0056
0057
V
W
0076 v
0077 w
0096 Ctrl
0097 Ctrl
00B6
00B7
00D6
00D7
00F6
00F7
bit code. 0018 CAN
0019 EM
0038 8
0039 9
0058
0059
X
Y
0078 x
0079 y
0098 Ctrl
0099 Ctrl
00B8
00B9 1
00D8
00D9
00F8
00F9
001A SUB 003A : 005A Z 007A z 009A Ctrl 00BA o 00DA 00FA
001B ESC 003B ; 005B [ 007B { 009B Ctrl 00BB 00DB 00FB
001C FS 003C < 005C \ 007C | 009C Ctrl 00BC 1/4 00DC 00FC
P
001D GS 003D = 005D ] 007D } 009D Ctrl 00BD 1/2 00DD Y 00FD P
001E RS 003E > 005E ^ 007E ~ 009E Ctrl 00BE 3/4 00DE y 00FE pp
001F US 003F ? 005F _ 007F DEL 009F Ctrl 00BF 00DF 00FF
NUL Null SOH Start of heading CAN Cancel SP Space
STX Start of text EOT End of transmission EM End of medium DEL Delete
ETX End of text DC1 Device control 1 SUB Substitute Ctrl Control
ENQ Enquiry DC2 Device control 2 ESC Escape FF Form feed
ACK Acknowledge DC3 Device control 3 FS File separator CR Carriage return
BEL Bell DC4 Device control 4 GS Group separator SO Shift out
BS Backspace NAK Negative acknowledge RS Record separator SI Shift in
HT Horizontal tab NBS Non-breaking space US Unit separator DLE Data link escape
LF Line feed ETB End of transmission block SYN Synchronous idle VT Vertical tab
Principles of Computer Architecture by M. Murdocca and V. Heuring 1999 M. Murdocca and V. Heuring