Computer Organization Computer Architectures Lab
DATA REPRESENTATION
Data Types
Complements
Fixed Point Representations
Floating Point Representations
Other Binary Codes
Error Detection Codes
2 Data Representation
Computer Organization Computer Architectures Lab
DATA REPRESENTATION
Information that a Computer is dealing with
* Data
 Numeric Data
Numbers( Integer, real)
 Nonnumeric Data
Letters, Symbols
* Relationship between data elements
 Data Structures
Linear Lists, Trees, Rings, etc
* Program(Instruction)
Data Types
3 Data Representation
Computer Organization Computer Architectures Lab
NUMERIC DATA REPRESENTATION
R = 10 Decimal number system, R = 2 Binary
R = 8 Octal, R = 16 Hexadecimal
Radix point(.) separates the integer
portion and the fractional portion
Data
Numeric data  numbers(integer, real)
Nonnumeric data  symbols, letters
Number System
Nonpositional number system
 Roman number system
Positional number system
 Each digit position has a value called a weight
associated with it
 Decimal, Octal, Hexadecimal, Binary
Base (or radix) R number
 Uses R distinct symbols for each digit
 Example A
R
= a
n1
a
n2
...
a
1
a
0
.a
1
…a
m
 V(A
R
) =
Data Types
¿
÷
÷ =
1 n
m i
i
i
R a
4 Data Representation
Computer Organization Computer Architectures Lab
WHY POSITIONAL NUMBER SYSTEM IN DIGITAL COMPUTERS ?
Major Consideration is the COST and TIME
 Cost of building hardware
Arithmetic and Logic Unit, CPU, Communications
 Time to processing
Arithmetic  Addition of Numbers  Table for Addition
* Nonpositional Number System
 Table for addition is infinite
> Impossible to build, very expensive even
if it can be built
* Positional Number System
 Table for Addition is finite
> Physically realizable, but cost wise
the smaller the table size, the less
expensive > Binary is favorable to Decimal
0 1
0 0 1
1 1 10
0 1 2 3 4 5 6 7 8 9
0 0 1 2 3 4 5 6 7 8 9
1 1 2 3 4 5 6 7 8 9 10
2 2 3 4 5 6 7 8 9 1011
3 3 4 5 6 7 8 9 101112
4 4 5 6 7 8 9 10111213
5 5 6 7 8 9 1011121314
6 6 7 8 9 101112131415
7 7 8 9 10111213141516
8 8 9 1011121314151617
9 9 101112131415161718
Binary Addition Table
Decimal Addition Table
Data Types
5 Data Representation
Computer Organization Computer Architectures Lab
REPRESENTATION OF NUMBERS  POSITIONAL NUMBERS
Decimal Binary Octal Hexadecimal
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Binary, octal, and hexadecimal conversion
1 0 1 0 1 1 1 1 0 1 1 0 0 0 1 1
1 2 7 5 4 3
A F 6 3
Octal
Binary
Hexa
Data Types
6 Data Representation
Computer Organization Computer Architectures Lab
CONVERSION OF BASES
Decimal to Base R number
Base R to Decimal Conversion
V(A) = E a
k
R
k
A = a
n1
a
n2
a
n3
… a
0
. a
1
… a
m
(736.4)
8
= 7 x 8
2
+ 3 x 8
1
+ 6 x 8
0
+ 4 x 8
1
= 7 x 64 + 3 x 8 + 6 x 1 + 4/8 = (478.5)
10
(110110)
2
= ... = (54)
10
(110.111)
2
= ... = (6.785)
10
(F3)
16
= ... = (243)
10
(0.325)
6
= ... = (0.578703703 .................)
10
 Separate the number into its integer and fraction parts and convert
each part separately.
 Convert integer part into the base R number
→ successive divisions by R and accumulation of the remainders.
 Convert fraction part into the base R number
→ successive multiplications by R and accumulation of integer
digits
Data Types
7 Data Representation
Computer Organization Computer Architectures Lab
EXAMPLE
Convert 41.6875
10
to base 2.
Integer = 41
41
20 1
10 0
5 0
2 1
1 0
0 1
Fraction = 0.6875
0.6875
x 2
1.3750
x 2
0.7500
x 2
1.5000
x 2
1.0000
(41)
10
= (101001)
2
(0.6875)
10
= (0.1011)
2
(41.6875)
10
= (101001.1011)
2
Convert (63)
10
to base 5: (223)
5
Convert (1863)
10
to base 8: (3507)
8
Convert (0.63671875)
10
to hexadecimal: (0.A3)
16
Exercise
Data Types
8 Data Representation
Computer Organization Computer Architectures Lab
COMPLEMENT OF NUMBERS
Two types of complements for base R number system:
 R's complement and (R1)'s complement
The (R1)'s Complement
Subtract each digit of a number from (R1)
Example
 9's complement of 835
10
is 164
10
 1's complement of 1010
2
is 0101
2
(bit by bit complement operation)
The R's Complement
Add 1 to the loworder digit of its (R1)'s complement
Example
 10's complement of 835
10
is 164
10
+ 1 = 165
10
 2's complement of 1010
2
is 0101
2
+ 1 = 0110
2
Complements
9 Data Representation
Computer Organization Computer Architectures Lab
FIXED POINT NUMBERS
Binary FixedPoint Representation
X = x
n
x
n1
x
n2
... x
1
x
0
. x
1
x
2
... x
m
Sign Bit(x
n
): 0 for positive  1 for negative
Remaining Bits(x
n1
x
n2
... x
1
x
0
. x
1
x
2
... x
m
)
Numbers: Fixed Point Numbers and Floating Point Numbers
Fixed Point Representations
10 Data Representation
Computer Organization Computer Architectures Lab
SIGNED NUMBERS
Signed magnitude representation
Signed 1's complement representation
Signed 2's complement representation
Example: Represent +9 and 9 in 7 bitbinary number
Only one way to represent +9 ==> 0 001001
Three different ways to represent 9:
In signedmagnitude: 1 001001
In signed1's complement: 1 110110
In signed2's complement: 1 110111
In general, in computers, fixed point numbers are represented
either integer part only or fractional part only.
Need to be able to represent both positive and negative numbers
 Following 3 representations
11 Data Representation
Computer Organization Computer Architectures Lab
CHARACTERISTICS OF 3 DIFFERENT REPRESENTATIONS
Complement
Signed magnitude: Complement only the sign bit
Signed 1's complement: Complement all the bits including sign bit
Signed 2's complement: Take the 2's complement of the number,
including its sign bit.
Maximum and Minimum Representable Numbers and Representation of Zero
X = x
n
x
n1
... x
0
. x
1
... x
m
Signed Magnitude
Max: 2
n
 2
m
011 ... 11.11 ... 1
Min: (2
n
 2
m
) 111 ... 11.11 ... 1
Zero: +0 000 ... 00.00 ... 0
0 100 ... 00.00 ... 0
Signed 1‟s Complement
Max: 2
n
 2
m
011 ... 11.11 ... 1
Min: (2
n
 2
m
) 100 ... 00.00 ... 0
Zero: +0 000 ... 00.00 ... 0
0 111 ... 11.11 ... 1
Fixed Point Representations
Signed 2‟s Complement
Max: 2
n
 2
m
011 ... 11.11 ... 1
Min: 2
n
100 ... 00.00 ... 0
Zero: 0 000 ... 00.00 ... 0
12 Data Representation
Computer Organization Computer Architectures Lab
2‟s COMPLEMENT REPRESENTATION WEIGHTS
• Signed 2‟s complement representation follows a “weight” scheme
similar to that of unsigned numbers
– Sign bit has negative weight
– Other bits have regular weights
X = x
n
x
n1
... x
0
V(X) =  x
n
× 2
n
+ x
i
× 2
i
i = 0
n1
13 Data Representation
Computer Organization Computer Architectures Lab
ARITHMETIC ADDITION: SIGNED MAGNITUDE
[1] Compare their signs
[2] If two signs are the same ,
ADD the two magnitudes  Look out for an overflow
[3] If not the same , compare the relative magnitudes of the numbers and
then SUBTRACT the smaller from the larger > need a subtractor to add
[4] Determine the sign of the result
6 0110
+) 9 1001
15 1111 > 01111
9 1001
 ) 6 0110
3 0011 > 00011
9 1001
) 6 0110
 3 0011 > 10011
6 0110
+) 9 1001
15 1111 > 11111
6 + 9 6 + 9
6 + ( 9) 6 + (9)
Overflow 9 + 9 or (9) + (9)
9 1001
+) 9 1001
(1)0010 overflow
Fixed Point Representations
14 Data Representation
Computer Organization Computer Architectures Lab
ARITHMETIC ADDITION: SIGNED 2‟s COMPLEMENT
Example
6 0 0110
9 0 1001
15 0 1111
6 1 1010
9 0 1001
3 0 0011
6 0 0110
9 1 0111
3 1 1101
9 1 0111
9 1 0111
18 (1)0 1110
Add the two numbers, including their sign bit, and discard any carry out of
leftmost (sign) bit  Look out for an overflow
overflow
9 0 1001
9 0 1001
+)
+)
+)
+) +)
18 1 0010
2 operands have the same sign
and the result sign changes
x
n1
y
n1
s‟
n1
+ x‟
n1
y‟
n1
s
n1
= c
n1
© c
n
x‟
n1
y‟
n1
s
n1
(c
n1
©
c
n
)
x
n1
y
n
s‟
n1
(c
n1
© c
n
)
Fixed Point Representations
15 Data Representation
Computer Organization Computer Architectures Lab
ARITHMETIC ADDITION: SIGNED 1‟s COMPLEMENT
Add the two numbers, including their sign bits.
 If there is a carry out of the most significant (sign) bit, the result is
incremented by 1 and the carry is discarded.
6 0 0110
9 1 0110
3 1 1100
6 1 1001
9 0 1001
(1) 0(1)0010
1
3 0 0011
+)
+)
+)
endaround carry
9 1 0110
9 1 0110
(1)0 1100
1
0 1101
+)
+)
9 0 1001
9 0 1001
1 (1)0010
+)
overflow
Example
not overflow (c
n1
© c
n
) = 0
(c
n1
© c
n
)
Fixed Point Representations
16 Data Representation
Computer Organization Computer Architectures Lab
COMPARISON OF REPRESENTATIONS
* Easiness of negative conversion
S + M > 1‟s Complement > 2‟s Complement
* Hardware
 S+M: Needs an adder and a subtractor for Addition
 1‟s and 2‟s Complement: Need only an adder
* Speed of Arithmetic
2‟s Complement > 1‟s Complement(endaround C)
* Recognition of Zero
2‟s Complement is fast
Fixed Point Representations
17 Data Representation
Computer Organization Computer Architectures Lab
ARITHMETIC SUBTRACTION
Take the complement of the subtrahend (including the sign bit)
and add it to the minuend including the sign bits.
( ± A )  (  B ) = ( ± A ) + B
( ± A )  B = ( ± A ) + (  B )
Fixed Point Representations
Arithmetic Subtraction in 2‟s complement
18 Data Representation
Computer Organization Computer Architectures Lab
FLOATING POINT NUMBER REPRESENTATION
* The location of the fractional point is not fixed to a certain location
* The range of the representable numbers is wide
F = EM
m
n
e
k
e
k1
... e
0
m
n1
m
n2
… m
0
. m
1
… m
m
sign exponent mantissa
 Mantissa
Signed fixed point number, either an integer or a fractional number
 Exponent
Designates the position of the radix point
Decimal Value
V(F) = V(M) * R
V(E)
M: Mantissa
E: Exponent
R: Radix
Floating Point Representation
19 Data Representation
Computer Organization Computer Architectures Lab
FLOATING POINT NUMBERS
0 .1234567 0 04
sign
sign
mantissa exponent
==> +.1234567 x 10
+04
Example
A binary number +1001.11 in 16bit floating point number representation
(6bit exponent and 10bit fractional mantissa)
0 0 00100 100111000
0 0 00101 010011100
Example
Note:
In Floating Point Number representation, only Mantissa(M) and
Exponent(E) are explicitly represented. The Radix(R) and the position
of the Radix Point are implied.
Exponent Mantissa Sign
or
Floating Point Representation
20 Data Representation
Computer Organization Computer Architectures Lab
CHARACTERISTICS OF FLOATING POINT NUMBER REPRESENTATIONS
Normal Form
 There are many different floating point number representations of
the same number
→ Need for a unified representation in a given computer
 the most significant position of the mantissa contains a nonzero digit
Representation of Zero
 Zero
Mantissa = 0
 Real Zero
Mantissa = 0
Exponent
= smallest representable number
which is represented as
00 ... 0
÷ Easily identified by the hardware
Floating Point Representation
21 Data Representation
Computer Organization Computer Architectures Lab
INTERNAL REPRESENTATION AND EXTERNAL REPRESENTATION
CPU
Memory
Internal
Representation
Human
Device
Another
Computer
External
Representation
External
Representation
External
Representation
22 Data Representation
Computer Organization Computer Architectures Lab
EXTERNAL REPRESENTATION
Decimal BCD Code
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
Numbers
Most of numbers stored in the computer are eventually changed
by some kinds of calculations
→ Internal Representation for calculation efficiency
→ Final results need to be converted to as External Representation
for presentability
Alphabets, Symbols, and some Numbers
Elements of these information do not change in the course of processing
→ No needs for Internal Representation since they are not used
for calculations
→ External Representation for processing and presentability
Example
Decimal Number: 4bit Binary Code
BCD(Binary Coded Decimal)
External Representations
23 Data Representation
Computer Organization Computer Architectures Lab
OTHER DECIMAL CODES
Decimal BCD(8421) 2421 8421 Excess3
0 0000 0000 0000 0011
1 0001 0001 0111 0100
2 0010 0010 0110 0101
3 0011 0011 0101 0110
4 0100 0100 0100 0111
5 0101 1011 1011 1000
6 0110 1100 1010 1001
7 0111 1101 1001 1010
8 1000 1110 1000 1011
9 1001 1111 1111 1100
d
3
d
2
d
1
d
0
: symbol in the codes
BCD: d
3
x 8 + d
2
x 4 + d
1
x 2 + d
0
x 1
¬ 8421 code.
2421: d
3
x 2 + d
2
x 4 + d
1
x 2 + d
0
x 1
8421: d
3
x 8 + d
2
x 4 + d
1
x (2) + d
0
x (1)
Excess3: BCD + 3
Note: 8,4,2,2,1,1 in this table is the weight
associated with each bit position.
BCD: It is difficult to obtain the 9's complement.
However, it is easily obtained with the other codes listed above.
→ Selfcomplementing codes
External Representations
24 Data Representation
Computer Organization Computer Architectures Lab
GRAY CODE
* Characterized by having their representations of the binary integers differ
in only one digit between consecutive integers
* Useful in some applications
Decimal
number
Gray Binary
g
3
g
2
g
1
g
0
b
3
b
2
b
1
b
0
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1
2 0 0 1 1 0 0 1 0
3 0 0 1 0 0 0 1 1
4 0 1 1 0 0 1 0 0
5 0 1 1 1 0 1 0 1
6 0 1 0 1 0 1 1 0
7 0 1 0 0 0 1 1 1
8 1 1 0 0 1 0 0 0
9 1 1 0 1 1 0 0 1
10 1 1 1 1 1 0 1 0
11 1 1 1 0 1 0 1 1
12 1 0 1 0 1 1 0 0
13 1 0 1 1 1 1 0 1
14 1 0 0 1 1 1 1 0
15 1 0 0 0 1 1 1 1
4bit Gray codes
Other Binary codes
25 Data Representation
Computer Organization Computer Architectures Lab
GRAY CODE  ANALYSIS
Letting g
n
g
n1
... g
1
g
0
be the (n+1)bit Gray code
for the binary number b
n
b
n1
... b
1
b
0
g
i
= b
i
© b
i+1
, 0 s i s n1
g
n
= b
n
and
b
ni
= g
n
© g
n1
© . . . © g
ni
b
n
= g
n
0 0 0 0 00 0 000
1 0 1 0 01 0 001
1 1 0 11 0 011
1 0 0 10 0 010
1 10 0 110
1 11 0 111
1 01 0 101
1 00 0 100
1 100
1 101
1 111
1 010
1 011
1 001
1 101
1 000
The Gray code has a reflection property
 easy to construct a table without calculation,
 for any n: reflect case n1 about a
mirror at its bottom and prefix 0 and 1
to top and bottom halves, respectively
Reflection of Gray codes
Note:
Other Binary codes
c
26 Data Representation
Computer Organization Computer Architectures Lab
CHARACTER REPRESENTATION ASCII
ASCII (American Standard Code for Information Interchange) Code
Other Binary codes
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
NUL
SOH
STX
ETX
EOT
ENQ
ACK
BEL
BS
HT
LF
VT
FF
CR
SO
SI
SP
!
“
#
$
%
&
„
(
)
*
+
,

.
/
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
m
n
„
a
b
c
d
e
f
g
h
I
j
k
l
m
n
o
P
q
r
s
t
u
v
w
x
y
z
{

}
~
DEL
0 1 2 3 4 5 6 7
DLE
DC1
DC2
DC3
DC4
NAK
SYN
ETB
CAN
EM
SUB
ESC
FS
GS
RS
US
LSB
(4 bits)
MSB (3 bits)
27 Data Representation
Computer Organization Computer Architectures Lab
CONTROL CHARACTER REPRESENTAION (ACSII)
NUL Null
SOH Start of Heading (CC)
STX Start of Text (CC)
ETX End of Text (CC)
EOT End of Transmission (CC)
ENQ Enquiry (CC)
ACK Acknowledge (CC)
BEL Bell
BS Backspace (FE)
HT Horizontal Tab. (FE)
LF Line Feed (FE)
VT Vertical Tab. (FE)
FF Form Feed (FE)
CR Carriage Return (FE)
SO Shift Out
SI Shift In
DLE Data Link Escape (CC)
(CC) Communication Control
(FE) Format Effector
(IS) Information Separator
Other Binary codes
DC1 Device Control 1
DC2 Device Control 2
DC3 Device Control 3
DC4 Device Control 4
NAK Negative Acknowledge (CC)
SYN Synchronous Idle (CC)
ETB End of Transmission Block (CC)
CAN Cancel
EM End of Medium
SUB Substitute
ESC Escape
FS File Separator (IS)
GS Group Separator (IS)
RS Record Separator (IS)
US Unit Separator (IS)
DEL Delete
28 Data Representation
Computer Organization Computer Architectures Lab
ERROR DETECTING CODES
Parity System
 Simplest method for error detection
 One parity bit attached to the information
 Even Parity and Odd Parity
Even Parity
 One bit is attached to the information so that
the total number of 1 bits is an even number
1011001 0
1010010 1
Odd Parity
 One bit is attached to the information so that
the total number of 1 bits is an odd number
1011001 1
1010010 0
Error Detecting codes
29 Data Representation
Computer Organization Computer Architectures Lab
Parity Bit Generation
For b
6
b
5
... b
0
(7bit information); even parity bit b
even
b
even
= b
6
© b
5
© ... © b
0
For odd parity bit
b
odd
= b
even
© 1 = b
even
PARITY BIT GENERATION
30 Data Representation
Computer Organization Computer Architectures Lab
PARITY GENERATOR AND PARITY CHECKER
Parity Generator Circuit (even parity)
b
6
b
5
b
4
b
3
b
2
b
1
b
0
b
even
Parity Checker
b
6
b
5
b
4
b
3
b
2
b
1
b
0
b
even
Even Parity
error indicator
Error Detecting codes
Data Representation
2
Data Types
DATA REPRESENTATION
Information that a Computer is dealing with * Data  Numeric Data Numbers( Integer, real)  Nonnumeric Data Letters, Symbols * Relationship between data elements  Data Structures Linear Lists, Trees, Rings, etc * Program(Instruction)
Computer Organization
Computer Architectures Lab
Data Representation
3
Data Types
NUMERIC DATA REPRESENTATION
Data Numeric data  numbers(integer, real) Nonnumeric data  symbols, letters Number System Nonpositional number system  Roman number system Positional number system  Each digit position has a value called a weight associated with it  Decimal, Octal, Hexadecimal, Binary Base (or radix) R number  Uses R distinct symbols for each digit  Example AR = an1 an2 ... a1 a0 .a1…am  V(AR ) =
i m
a R
i
n 1
i
Radix point(.) separates the integer portion and the fractional portion R = 2 Binary R = 16 Hexadecimal
Computer Architectures Lab
R = 10 Decimal number system, R = 8 Octal,
Computer Organization
Communications .Table for Addition Binary Addition Table 0 1 1 10 0 1 0 1 * Nonpositional Number System . very expensive even if it can be built * Positional Number System .Addition of Numbers .Cost of building hardware Arithmetic and Logic Unit.Table for Addition is finite > Physically realizable. but cost wise the smaller the table size.Data Representation 4 Data Types WHY POSITIONAL NUMBER SYSTEM IN DIGITAL COMPUTERS ? Major Consideration is the COST and TIME . CPU.Time to processing Arithmetic .Table for addition is infinite > Impossible to build. the less expensive > Binary is favorable to Decimal Computer Organization Decimal Addition Table 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 1011 3 4 5 6 7 8 9 101112 4 5 6 7 8 9 10111213 5 6 7 8 9 1011121314 6 7 8 9 101112131415 7 8 9 10111213141516 8 9 1011121314151617 9 101112131415161718 Computer Architectures Lab .
POSITIONAL NUMBERS Decimal Binary Octal Hexadecimal 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 0 1 2 3 4 5 6 7 8 9 A B C D E F Binary. octal.Data Representation 5 Data Types REPRESENTATION OF NUMBERS . and hexadecimal conversion Octal 1 2 7 5 4 3 Binary 1 0 1 0 1 1 1 1 0 1 1 0 0 0 1 1 Hexa A F 6 3 Computer Organization Computer Architectures Lab .
= (54)10 (110.4)8 = 7 x 82 + 3 x 81 + 6 x 80 + 4 x 81 = 7 x 64 + 3 x 8 + 6 x 1 + 4/8 = (478.....)10 Decimal to Base R number ... .785)10 (F3)16 = ... = (0..Convert integer part into the base R number → successive divisions by R and accumulation of the remainders.. = (6..111)2 = . = (243)10 (0..Separate the number into its integer and fraction parts and convert each part separately....Data Representation 6 Data Types CONVERSION OF BASES Base R to Decimal Conversion A = an1 an2 an3 … a0 .5)10 (110110)2 = .578703703 ..Convert fraction part into the base R number → successive multiplications by R and accumulation of integer digits Computer Organization Computer Architectures Lab .... a1 … am V(A) = ak Rk (736..... .325)6 = ..
7500 x 2 1. Integer = 41 41 20 1 10 0 5 0 2 1 1 0 0 1 (41)10 = (101001)2 (41.5000 x 2 1.3750 x 2 0.1011)2 .1011)2 Exercise Convert (63)10 to base 5: (223)5 Convert (1863)10 to base 8: (3507)8 Convert (0.6875 0.6875)10 = (0.A3)16 Computer Organization Computer Architectures Lab Fraction = 0.6875)10 = (101001.Data Representation 7 Data Types EXAMPLE Convert 41.687510 to base 2.0000 (0.6875 x 2 1.63671875)10 to hexadecimal: (0.
1's complement of 10102 is 01012(bit by bit complement operation) The R's Complement Add 1 to the loworder digit of its (R1)'s complement Example .Data Representation 8 Complements COMPLEMENT OF NUMBERS Two types of complements for base R number system: .10's complement of 83510 is 16410 + 1 = 16510 .9's complement of 83510 is 16410 .R's complement and (R1)'s complement The (R1)'s Complement Subtract each digit of a number from (R1) Example .2's complement of 10102 is 01012 + 1 = 01102 Computer Organization Computer Architectures Lab .
.... xm Sign Bit(xn): 0 for positive . x1x2 .Data Representation 9 Fixed Point Representations FIXED POINT NUMBERS Numbers: Fixed Point Numbers and Floating Point Numbers Binary FixedPoint Representation X = xnxn1xn2 . x1x0. x1x2 .. xm) Computer Organization Computer Architectures Lab . x1x0.1 for negative Remaining Bits(xn1xn2 ....
fixed point numbers are represented either integer part only or fractional part only.Data Representation 10 SIGNED NUMBERS Need to be able to represent both positive and negative numbers .Following 3 representations Signed magnitude representation Signed 1's complement representation Signed 2's complement representation Example: Represent +9 and 9 in 7 bitbinary number Only one way to represent +9 ==> 0 001001 Three different ways to represent 9: In signedmagnitude: 1 001001 In signed1's complement: 1 110110 In signed2's complement: 1 110111 In general. Computer Organization Computer Architectures Lab . in computers.
0 000 . 11.. 00. 00. 11....00 . 00...00 . 00....... xm Signed Magnitude Max: 2n .11 .. 0 0 100 . 00...00 . Maximum and Minimum Representable Numbers and Representation of Zero X = xn xn1 ... 1 100 . 1 Min: (2n ...2m) Zero: +0 0 011 .11 .11 ..00 ..2m) 111 ...2m Min: 2n Zero: 0 011 ...Data Representation 11 Fixed Point Representations CHARACTERISTICS OF 3 DIFFERENT REPRESENTATIONS Complement Signed magnitude: Complement only the sign bit Signed 1's complement: Complement all the bits including sign bit Signed 2's complement: Take the 2's complement of the number... 1 Zero: +0 000 . 0 111 .. 1 100 ......11 . 00. x1 .. 0 000 . x0 ...00 ... 1 Signed 2‟s Complement Max: 2n .2m Min: (2n .... including its sign bit..... 11.2m 011 . 0 Computer Organization Computer Architectures Lab .00 .. 11.. 11.. 0 Signed 1‟s Complement Max: 2n .11 .
x0 V(X) = .Data Representation 12 2‟s COMPLEMENT REPRESENTATION WEIGHTS • Signed 2‟s complement representation follows a “weight” scheme similar to that of unsigned numbers – Sign bit has negative weight – Other bits have regular weights X = xn xn1 ..xn 2n + n1 xi 2i i=0 Computer Organization Computer Architectures Lab ..
Look out for an overflow [3] If not the same .9) 9 1001 ) 6 0110 . compare the relative magnitudes of the numbers and then SUBTRACT the smaller from the larger > need a subtractor to add [4] Determine the sign of the result 6+9 6 +) 9 15 0110 1001 1111 > 01111 9 )6 3 6 + 9 1001 0110 0011 > 00011 6 + (9) 6 0110 +) 9 1001 15 1111 > 11111 6 + (.Data Representation 13 Fixed Point Representations ARITHMETIC ADDITION: SIGNED MAGNITUDE [1] Compare their signs [2] If two signs are the same .3 0011 > 10011 Overflow 9 + 9 or (9) + (9) 9 1001 +) 9 1001 overflow (1)0010 Computer Organization Computer Architectures Lab . ADD the two magnitudes .
Data Representation 14 Fixed Point Representations ARITHMETIC ADDITION: SIGNED 2‟s COMPLEMENT Add the two numbers. and discard any carry out of leftmost (sign) bit .Look out for an overflow Example 6 0 0110 +) 9 0 1001 15 0 1111 6 0 0110 +) 9 1 0111 3 1 1101 6 +) 9 3 1 1010 0 1001 0 0011 9 1 0111 1 0111 +) 9 18 (1)0 1110 x‟n1y‟n1sn1 (cn1 cn) 9 0 1001 +) 9 0 1001 18 1 0010 xn1yn s‟n1 (cn1 cn) Computer Organization overflow 2 operands have the same sign and the result sign changes xn1yn1s‟n1 + x‟n1y‟n1sn1 = cn1 cn Computer Architectures Lab . including their sign bit.
If there is a carry out of the most significant (sign) bit. .Data Representation 15 Fixed Point Representations ARITHMETIC ADDITION: SIGNED 1‟s COMPLEMENT Add the two numbers. including their sign bits. Example +) 6 9 3 0 0110 1 0110 1 1100 endaround carry 6 1 1001 +) 9 0 1001 (1) 0(1)0010 1 +) 3 0 0011 not overflow (cn1 9 0 1001 9 0 1001 1 (1)0010 cn) = 0 +) +) 9 1 0110 9 1 0110 (1)0 1100 1 0 1101 +) overflow (cn1 cn) Computer Organization Computer Architectures Lab . the result is incremented by 1 and the carry is discarded.
Data Representation 16 Fixed Point Representations COMPARISON OF REPRESENTATIONS * Easiness of negative conversion S + M > 1‟s Complement > 2‟s Complement * Hardware .S+M: Needs an adder and a subtractor for Addition .1‟s and 2‟s Complement: Need only an adder * Speed of Arithmetic 2‟s Complement > 1‟s Complement(endaround C) * Recognition of Zero 2‟s Complement is fast Computer Organization Computer Architectures Lab .
B=(A)+( B) Computer Organization Computer Architectures Lab .Data Representation 17 Fixed Point Representations ARITHMETIC SUBTRACTION Arithmetic Subtraction in 2‟s complement Take the complement of the subtrahend (including the sign bit) and add it to the minuend including the sign bits. (A)(B) =(A)+ B (A).
. either an integer or a fractional number .Mantissa Signed fixed point number. e0 mn1mn2 … m0 . m1 … mm sign exponent mantissa .Data Representation 18 Floating Point Representation FLOATING POINT NUMBER REPRESENTATION * The location of the fractional point is not fixed to a certain location * The range of the representable numbers is wide F = EM mn ekek1 .Exponent Designates the position of the radix point Decimal Value V(F) = V(M) * RV(E) M: Mantissa E: Exponent R: Radix Computer Architectures Lab Computer Organization ..
only Mantissa(M) and Exponent(E) are explicitly represented.1234567 x 10+04 sign 0 04 exponent Note: In Floating Point Number representation.11 in 16bit floating point number representation (6bit exponent and 10bit fractional mantissa) 0 or Sign 0 00100 100111000 Exponent Mantissa 0 0 00101 010011100 Computer Organization Computer Architectures Lab .1234567 mantissa ==> +. Example A binary number +1001. The Radix(R) and the position of the Radix Point are implied.Data Representation 19 Floating Point Representation FLOATING POINT NUMBERS Example sign 0 .
There are many different floating point number representations of the same number → Need for a unified representation in a given computer . 0 Easily identified by the hardware Computer Organization Computer Architectures Lab ..Data Representation 20 Floating Point Representation CHARACTERISTICS OF FLOATING POINT NUMBER REPRESENTATIONS Normal Form .Real Zero Mantissa = 0 Exponent = smallest representable number which is represented as 00 ..the most significant position of the mantissa contains a nonzero digit Representation of Zero .Zero Mantissa = 0 .
Data Representation 21 INTERNAL REPRESENTATION AND EXTERNAL REPRESENTATION Another Computer External Representation External Representation Internal Representation CPU Memory Human Device External Representation Computer Organization Computer Architectures Lab .
Data Representation 22 External Representations EXTERNAL REPRESENTATION Numbers Most of numbers stored in the computer are eventually changed by some kinds of calculations → Internal Representation for calculation efficiency → Final results need to be converted to as External Representation for presentability Alphabets. and some Numbers Elements of these information do not change in the course of processing → No needs for Internal Representation since they are not used for calculations → External Representation for processing and presentability Example Decimal Number: 4bit Binary Code BCD(Binary Coded Decimal) Decimal 0 1 2 3 4 5 6 7 8 9 BCD Code 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 Computer Organization Computer Architectures Lab . Symbols.
Data Representation 23 External Representations OTHER DECIMAL CODES Decimal BCD(8421) 2421 8421 Excess3 0 1 2 3 4 5 6 7 8 9 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 0000 0000 0001 0111 0010 0110 0011 0101 0100 0100 1011 1011 1100 1010 1101 1001 1110 1000 1111 1111 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 Note: 8. However.2.4.1 in this table is the weight associated with each bit position.1. 2421: d3 x 2 + d2 x 4 + d1 x 2 + d0 x 1 8421: d3 x 8 + d2 x 4 + d1 x (2) + d0 x (1) Excess3: BCD + 3 BCD: It is difficult to obtain the 9's complement. it is easily obtained with the other codes listed above. → Selfcomplementing codes Computer Organization Computer Architectures Lab .2. d3 d2 d1 d0: symbol in the codes BCD: d3 x 8 + d2 x 4 + d1 x 2 + d0 x 1 8421 code.
Data Representation 24 Other Binary codes GRAY CODE * Characterized by having their representations of the binary integers differ in only one digit between consecutive integers * Useful in some applications Gray Decimal number g3 g2 g1 g0 0 0 0 0 0 1 0 0 0 1 2 0 0 1 1 3 0 0 1 0 4 0 1 1 0 5 0 1 1 1 6 0 1 0 1 7 0 1 0 0 8 1 1 0 0 9 1 1 0 1 10 1 1 1 1 11 1 1 1 0 12 1 0 1 0 13 1 0 1 1 14 1 0 0 1 15 1 0 0 0 Binary b3 b2 b1 b0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 Computer Architectures Lab 4bit Gray codes Computer Organization .
. respectively Computer Organization Computer Architectures Lab . . g1 g0 be the (n+1)bit Gray code for the binary number bnbn1 .ANALYSIS Letting gngn1 .. .easy to construct a table without calculation.. gni b n = gn Reflection of Gray codes 0 1 0 0 1 1 0 1 1 0 0 0 0 0 1 1 1 1 00 01 11 10 10 11 01 00 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 000 001 011 010 110 111 101 100 100 101 111 010 011 001 101 000 Note: The Gray code has a reflection property . 0 i n1 g n = bn and bni = gn gn1 ..for any n: reflect case n1 about a mirror at its bottom and prefix 0 and 1 to top and bottom halves. b1b0 gi = bi bi+1 ..Data Representation 25 Other Binary codes GRAY CODE .
< = > ? 4 @ A B C D E F G H I J K L M N O 5 P Q R S T U V W X Y Z [ \ ] m n 6 „ a b c d e f g h I j k l m n o 7 P q r s t u v w x y z {  } ~ DEL Computer Architectures Lab Computer Organization . / 3 0 1 2 3 4 5 6 7 8 9 : . .Data Representation 26 Other Binary codes CHARACTER REPRESENTATION ASCII ASCII (American Standard Code for Information Interchange) Code MSB (3 bits) 0 LSB (4 bits) 0 1 2 3 4 5 6 7 8 9 A B C D E F NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI 1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 2 SP ! “ # $ % & „ ( ) * + .
(FE) Line Feed (FE) Vertical Tab. (FE) Form Feed (FE) Carriage Return (FE) Shift Out Shift In Data Link Escape (CC) DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US DEL Device Control 1 Device Control 2 Device Control 3 Device Control 4 Negative Acknowledge (CC) Synchronous Idle (CC) End of Transmission Block (CC) Cancel End of Medium Substitute Escape File Separator (IS) Group Separator (IS) Record Separator (IS) Unit Separator (IS) Delete (CC) Communication Control (FE) Format Effector (IS) Information Separator Computer Organization Computer Architectures Lab .Data Representation 27 Other Binary codes CONTROL CHARACTER REPRESENTAION (ACSII) NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE Null Start of Heading (CC) Start of Text (CC) End of Text (CC) End of Transmission (CC) Enquiry (CC) Acknowledge (CC) Bell Backspace (FE) Horizontal Tab.
Data Representation 28 Error Detecting codes ERROR DETECTING CODES Parity System .Even Parity and Odd Parity Even Parity .One bit is attached to the information so that the total number of 1 bits is an even number 1011001 0 1010010 1 Odd Parity .One parity bit attached to the information .One bit is attached to the information so that the total number of 1 bits is an odd number 1011001 1 1010010 0 Computer Organization Computer Architectures Lab .Simplest method for error detection .
.. even parity bit beven beven = b6 b5 .Data Representation 29 PARITY BIT GENERATION Parity Bit Generation For b6b5. b0(7bit information).. b0 For odd parity bit bodd = beven 1 = beven Computer Organization Computer Architectures Lab ..
Data Representation 30 Error Detecting codes PARITY GENERATOR AND PARITY CHECKER Parity Generator Circuit (even parity) b6 b5 b4 b3 b2 b1 b0 beven Parity Checker beven b6 b5 b4 b3 b2 b1 b0 Computer Organization Even Parity error indicator Computer Architectures Lab .