Data Representation
Binary
Octal
Fixed Point
Instructions
Numerical Decimal
Information
Floating Point
Data Hexa Decimal
Non Numeric
Data Representation- Integer-Fixed
point
Unsigned Number
Signed Number
One’s Complement
Two’s Complement
Biased one(Not Commonly used)
Cont
Unsigned numbers: only non-negative values.
Signed numbers: include all values (positive and
negative).
There are three common ways of representing signed
numbers (positive and negative numbers) for binary
numbers:
Sign-and-Magnitude
1s Complement
2s Complement
Sign-and-Magnitude
Negative numbers are usually written by writing a minus
sign in front.
Example:
- (12)10 , - (1100)2
In sign-and-magnitude representation, this sign is usually
represented by a bit:
0 for +
1 for -
Negative Numbers:
Sign-and-Magnitude (Cont’)
Example: an 8-bit number can have 1-bit sign and 7-
bit magnitude.
sign magnitude
Signed magnitude representation
(cont’)
.
Examples:
7
Negative Numbers:
Sign-and-Magnitude (Cont’)
10
Why is it called “one’s complement?”
Complementing a single bit is equivalent to subtracting the bit from 1.
0’ = 1, and 1 - 0 = 1 1’ = 0, and 1 - 1 = 0
1 1 1 1 1
- 0 1 1 0 1
1 0 0 1 0
11
1s Complement Addition/Subtraction
Algorithm for addition, A + B:
1. Perform binary addition on the two numbers.
2. If there is a carry out of the MSB, add 1 to the result.
3. Check for overflow: Overflow occurs if result is opposite sign
of A and B.
13
Two’s complement
Our final idea is two’s complement. To negate a number, complement each bit (just as
for ones’ complement) and then add 1.
Examples:
11012 = 1310 (a 4-bit unsigned number)
0 1101 = +1310 (a positive number in 5-bit two’s complement)
1 0010 = -1310 (a negative number in 5-bit ones’ complement)
1 0011 = -1310 (a negative number in 5-bit two’s complement)
14
2s Complement Addition/Subtraction
Algorithm for addition, A + B:
1. Perform binary addition on the two numbers.
2. Ignore the carry out of the MSB (most significant bit).
3. Check for overflow: Overflow occurs if the ‘carry in’ and ‘carry
out’ of the MSB are different, or if result is opposite sign of A
and B.
+3 0011 -2 1110
+ +4 + 0100 + -6 + 1010
---- ------- ---- -------
+7 0111 -8 11000
---- ------- ---- -------
+6 0110 +4 0100
+ -3 + 1101 + -7 + 1001
---- ------- ---- -------
+3 10011 -3 1101
---- ------- ---- -------
We cannot just include the carry out to produce a five-digit result, as for
unsigned addition. If we did, (-4) + (-5) would result in +23!
Also, unlike the case with unsigned numbers, the carry out cannot be
used to detect overflow.
In the example on the left, the carry out is 0 but there is overflow.
Conversely, there are situations where the carry out is 1 but there is
no overflow.
18 Subtraction (lvk)
Detecting signed overflow
The easiest way to detect signed overflow is to look at all the sign bits.
19 Subtraction (lvk)
Signed Overflow
21
Ranges of the signed number systems
How many negative and positive numbers can be represented in each of the different
systems on the previous page?
In general, with n-bit numbers including the sign, the ranges are:
binary point
In mathematics, radix point refers to the symbol used in numerical representations to separate the integral part of the
number (to the left of the radix) from its fractional part (to the right of the radix). The radix point is usually a small dot,
either placed on the baseline or halfway between the baseline and the top of the numerals. In base 10, the radix point is
more commonly called the decimal point. ... From en.wikipedia.org/wiki/Radix_point 24
Sign bit Floating Point
25
Signs for Floating Point
26
Normalization
FP numbers are usually normalized
exponent is adjusted so that leading bit (MSB) of mantissa is 1
Since it is always 1 there is no need to store it
(Scientific notation where numbers are normalized to give a single digit
before the decimal point e.g. 3.123 x 103)
In FP representation: not representing more individual values,
but spreading the numbers.
27
Expressible Numbers
28
IEEE 754
29
Floating-point Format
• Various floating-point formats have been defined,
such as the UNIVAC 1100, CDC 3600 and IEEE
Standard 754
(a) UNIVAC 1100
27 bits 9 bits
Mantissa Exponent
Single precision
60 bits 12 bits
Mantissa Exponent
Double precision
Exponent Mantissa
Exponent sign
Mantissa sign
30
IEEE Floating-point Format
• IEEE has introduced a standard floating-point
format for arithmetic operations in mini and
microcomputer, which is defined in IEEE Standard
754
• In this format, the numbers are normalized so that
the significand or mantissa lie in the range 1F<2,
which corresponds to an integer part equal to 1
• An IEEE format floating-point number X is formally
defined as:
EB
X 1 x 2
S
x 1.F
where S = sign bit [0+, 1]
E = exponent biased by B
F = fractional mantissa 31
• Two basics format are defined in the IEEE
Standard 754
• These are the 32-bit single and 64-bit double
formats, with 8-bit and 11-bit exponent respectively
Sign
8 bits 23 bits
bit
Biased
Significand
Exponent
Sign
11 bits 52 bits
bit
32
Floating Point Examples
negative
20 127 + 20 = 147
negativ
e
normalized
-20 127 - 20 = 107
...
stored [23 bits]
– 6 + 127 = 133101 0 0 1 1 0 1 1 0 1 1 0 ...
1 1 0 0 0 0 1 0 1 0 0 1 1 0 1 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
sign biased exponent significand
34
Convert these IEEE single precision floating-point
numbers to their decimal equivalent:
= 5000.12510
-1.11110011111112 x 29 = -1111100111.11112
= -999.937510
Slides adapted from
tan wooi haw’s lecture
notes (FOE)
35
Character Representation ASCII
ASCII (American Standard Code for Information Interchange) Code
MSB (3 bits)
0 1 2 3 4 5 6 7
http://acad.intranet.vit.ac.in/CoursePage/COURSEPAGE-
DUMP/EEE116%20Digital%20Logic%20System
%20Design/Prof.%20Balamurugan%20%20S/Unit-I-
Number%20system%20and%20Codes.ppt
Data Representation
1
Data Representation
Binary
Octal
Fixed Point
Instructions
Numerical Decimal
Information
Floating Point
Data Hexa Decimal
Non Numeric
Data Representation- Integer-Fixed
point
Unsigned Number
Signed Number
One’s Complement
Two’s Complement
Biased one(Not Commonly used)
3
Cont
Unsigned numbers: only non-negative values.
Signed numbers: include all values (positive and
negative).
There are three common ways of representing signed
numbers (positive and negative numbers) for binary
numbers:
Sign-and-Magnitude
1s Complement
2s Complement
Sign-and-Magnitude
Negative numbers are usually written by writing a minus
sign in front.
Example:
- (12)10 , - (1100)2
In sign-and-magnitude representation, this sign is usually
represented by a bit:
0 for +
1 for -
Negative Numbers:
Sign-and-Magnitude (Cont’)
Example: an 8-bit number can have 1-bit sign and 7-
bit magnitude.
sign magnitude
Signed magnitude representation
(cont’)
.
Examples:
7
Negative Numbers:
Sign-and-Magnitude (Cont’)
10
Why is it called “one’s complement?”
Complementing a single bit is equivalent to subtracting the bit from 1.
0’ = 1, and 1 - 0 = 1 1’ = 0, and 1 - 1 = 0
1 1 1 1 1
- 0 1 1 0 1
1 0 0 1 0
11
1s Complement Addition/Subtraction
Algorithm for addition, A + B:
1. Perform binary addition on the two numbers.
2. If there is a carry out of the MSB, add 1 to the result.
3. Check for overflow: Overflow occurs if result is opposite sign
of A and B.
13
Two’s complement
Our final idea is two’s complement. To negate a number, complement each bit (just as
for ones’ complement) and then add 1.
Examples:
11012 = 1310 (a 4-bit unsigned number)
0 1101 = +1310 (a positive number in 5-bit two’s complement)
1 0010 = -1310 (a negative number in 5-bit ones’ complement)
1 0011 = -1310 (a negative number in 5-bit two’s complement)
14
2s Complement Addition/Subtraction
Algorithm for addition, A + B:
1. Perform binary addition on the two numbers.
2. Ignore the carry out of the MSB (most significant bit).
3. Check for overflow: Overflow occurs if the ‘carry in’ and ‘carry
out’ of the MSB are different, or if result is opposite sign of A
and B.
+3 0011 -2 1110
+ +4 + 0100 + -6 + 1010
---- ------- ---- -------
+7 0111 -8 11000
---- ------- ---- -------
+6 0110 +4 0100
+ -3 + 1101 + -7 + 1001
---- ------- ---- -------
+3 10011 -3 1101
---- ------- ---- -------
We cannot just include the carry out to produce a five-digit result, as for
unsigned addition. If we did, (-4) + (-5) would result in +23!
Also, unlike the case with unsigned numbers, the carry out cannot be
used to detect overflow.
In the example on the left, the carry out is 0 but there is overflow.
Conversely, there are situations where the carry out is 1 but there is
no overflow.
18 Subtraction (lvk)
Detecting signed overflow
The easiest way to detect signed overflow is to look at all the sign bits.
19 Subtraction (lvk)
Signed Overflow
20
Comparing the signed number systems
Here are all the 4-bit numbers
Decimal S.M. 1’s comp. 2’s comp.
in the different systems.
7 0111 0111 0111
Positive numbers are the same in 6 0110 0110 0110
all three representations.
5 0101 0101 0101
Signed magnitude and one’s 4 0100 0100 0100
complement have two ways of 3 0011 0011 0011
representing 0. This makes
2 0010 0010 0010
things more complicated.
1 0001 0001 0001
Two’s complement has 0 0000 0000 0000
asymmetric ranges; there is
one more negative number -0 1000 1111 —
than positive number. Here, -1 1001 1110 1111
you can represent -8 but not -2 1010 1101 1110
+8. -3 1011 1100 1101
However, two’s complement -4 1100 1011 1100
is preferred because it has only -5 1101 1010 1011
one 0, and its addition -6 1110 1001 1010
algorithm is the simplest. -7 1111 1000 1001
-8 — — 1000
21
Ranges of the signed number systems
How many negative and positive numbers can be represented in each of the different
systems on the previous page?
In general, with n-bit numbers including the sign, the ranges are:
binary point
In mathematics, radix point refers to the symbol used in numerical representations to separate the integral part of the
number (to the left of the radix) from its fractional part (to the right of the radix). The radix point is usually a small dot,
either placed on the baseline or halfway between the baseline and the top of the numerals. In base 10, the radix point is
more commonly called the decimal point. ... From en.wikipedia.org/wiki/Radix_point 24
Floating Point
Sign bit
Biased Significand or Mantissa
Exponent
25
Signs for Floating Point
26
Normalization
FP numbers are usually normalized
exponent is adjusted so that leading bit (MSB) of mantissa is 1
Since it is always 1 there is no need to store it
(Scientific notation where numbers are normalized to give a single digit
before the decimal point e.g. 3.123 x 103)
In FP representation: not representing more individual values,
but spreading the numbers.
27
Expressible Numbers
28
IEEE 754
29
Floating-point Format
• Various floating-point formats have been defined,
such as the UNIVAC 1100, CDC 3600 and IEEE
Standard 754
(a) UNIVAC 1100
27 bits 9 bits
Mantissa Exponent
Single precision
60 bits 12 bits
Mantissa Exponent
Double precision
Exponent Mantissa
Exponent sign
Mantissa sign
30
IEEE Floating-point Format
• IEEE has introduced a standard floating-point
format for arithmetic operations in mini and
microcomputer, which is defined in IEEE Standard
754
• In this format, the numbers are normalized so that
the significand or mantissa lie in the range 1F<2,
which corresponds to an integer part equal to 1
• An IEEE format floating-point number X is formally
defined as:
X 1S x 2 E B x 1.F
where S = sign bit [0+, 1]
E = exponent biased by B
F = fractional mantissa 31
• Two basics format are defined in the IEEE
Standard 754
• These are the 32-bit single and 64-bit double
formats, with 8-bit and 11-bit exponent respectively
Sign
8 bits 23 bits
bit
Biased
Significand
Exponent
Sign
11 bits 52 bits
bit
32
Floating Point Examples
negative
20 127 + 20 = 147
negativ
e
normalized
-20 127 - 20 = 107
...
stored [23 bits]
– 6 + 127 = 133101 0 0 1 1 0 1 1 0 1 1 0 ...
1 1 0 0 0 0 1 0 1 0 0 1 1 0 1 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
sign biased exponent significand
34
Convert these IEEE single precision floating-point
numbers to their decimal equivalent:
= 5000.12510
-1.11110011111112 x 29 = -1111100111.11112
= -999.937510
Slides adapted from
tan wooi haw’s lecture
notes (FOE)
35
Character Representation ASCII
ASCII (American Standard Code for Information Interchange) Code
MSB (3 bits)
0 1 2 3 4 5 6 7
36
Control Character Representation
(ASCII)
NUL Null DC1 Device Control 1
SOH Start of Heading (CC) DC2 Device Control 2
STX Start of Text (CC) DC3 Device Control 3
ETX End of Text (CC) DC4 Device Control 4
EOT End of Transmission (CC) NAK Negative Acknowledge (CC)
ENQ Enquiry (CC) SYN Synchronous Idle (CC)
ACK Acknowledge (CC) ETB End of Transmission Block (CC)
BEL Bell CAN Cancel
BS Backspace (FE) EM End of Medium
HT Horizontal Tab. (FE) SUB Substitute
LF Line Feed (FE) ESC Escape
VT Vertical Tab. (FE) FS File Separator (IS)
FF Form Feed (FE) GS Group Separator (IS)
CR Carriage Return (FE) RS Record Separator (IS)
SO Shift Out US Unit Separator (IS)
SI Shift In DEL Delete
DLE Data Link Escape (CC)
(CC) Communication Control
(FE) Format Effector
(IS) Information Separator
37
The EBCDIC character code, shown with
hexadecimal indices
38
The EBCDIC control character
representation
39
Pros and cons of integer
representation
Signed magnitude representation:
2 representations for 0
Simple
255 different numbers can be represented.
Need to consider both sign and magnitude in arithmetic
Different logic for addition and subtraction
1’s complement representation:
2 representations for 0
Complexity in performing addition and subtraction
255 different numbers can be represented.
2’s complement representation:
Only one representation for 0
256 different numbers can be represented.
Arithmetic works easily
Negating is fairly easy
40
Reference
Morris Mano, “Computer System Architecture”, Pearson
Education, 3rd edition (Chapter 3)
http://acad.intranet.vit.ac.in/CoursePage/COURSEPAGE-
DUMP/EEE116%20Digital%20Logic%20System
%20Design/Prof.%20Balamurugan%20%20S/Unit-I-
Number%20system%20and%20Codes.ppt