Professional Documents
Culture Documents
Chapter 2
Chapter 2
Data Representation in
Computer Systems
Chapter 2 Objectives
2
Introduction
• In chapter 1, we briefly saw that computer technology is based
on integrated circuits (IC), which themselves are based on
transistors
– The idea is that ICs store circuits that operate on electrical current by
either letting current pass through, or blocking the current
• So, we consider every circuit in the computer to be in a state of on or off (1 or 0)
• Because of this, the computer can store information in binary form
• But we want to store information from the real world, information that consists
of numbers, names, sounds, pictures, instructions
– So we need to create a representation for these types of information
using nothing but 0s and 1s
• That’s the topic for this chapter
3
Introduction
• A bit is the most basic unit of information in a computer
• A byte is a group of eight bits, the smallest possible
addressable unit of computer storage.
– The term, “addressable,” means that a particular byte can be
retrieved according to its location in memory
• A word is a contiguous group of bytes.
– Word sizes of 16, 32, or 64 bits are most common.
– In a word-addressable system, a word is the smallest
addressable unit of storage.
• A group of four bits is called a nibble (or nybble).
4
2.2 Positional Numbering Systems
5
2.2 Positional Numbering Systems
9 10 2 + 4 10 1 + 7 10 0
5 10 3 + 8 10 2 + 3 10 1 + 6 10 0
+ 4 10 -1 + 7 10 -2
6
2.2 Positional Numbering Systems
7
2.3 Decimal to Binary Conversions
8
2.3 Decimal to Binary Conversions
9
Using division to convert integers from
decimal to some other radix.
10
2.3 Decimal to Binary Conversions
11
2.3 Decimal to Binary Conversions
12
2.3 Decimal to Binary Conversions
14
Hexadecimal
• The binary numbering system is the most important radix system
for digital computers
• However, it is difficult to read long strings of binary numbers
• For compactness and ease of reading, binary values are usually
expressed using the hexadecimal
• The hexadecimal numbering system uses the numerals 0 through 9
and the letters A through F.
– The decimal number 26 is 1A16.
• Thus, to convert from binary to hexadecimal, all we need to do is
group the binary digits into groups of four.
15
2.3 Decimal to Binary Conversions
18
Example one
We were careful to pick two values whose sum would fit into 7 bits. If that is
19
Example Two
We see that the carry from the seventh bit overflows and
is discarded, giving us the erroneous result
107 + 46 = 25
20
Example Three
22
Signed Magnitude Representation
• Advantage
– easy for people to understand.
• Disadvantage of signed magnitude
– It allows 2 different representations for zero: positive
zero and negative zero.
– It requires complicated computer hardware
• For these reasons (among others) computers
systems employ Complement systems for
numeric value representation.
23
Complement Systems
• In complement systems, negative values are represented
by some difference between a number and its base.
• In diminished radix complement systems, a negative
value is given by the difference between the absolute value
of a number and one less than its base.
• In the binary system, this gives us one’s complement.
– It amounts to little more than flipping the bits of a binary number
24
One’s Complement
• With one’s complement addition, the carry bit is “carried
around” and added to the sum.
• In 8-bit one’s complement
• positive 3 is: 00000011
• Negative 3 is: 11111100
• In one’s complement, as with signed magnitude, negative
values are indicated by a 1 in the high order bit.
• Complement systems are useful because they eliminate
the need for subtraction.
• The difference of two values is found by adding the
minuend to the complement of the subtrahend.
25
One’s Complement
Example One
Using one’s complement binary arithmetic, find the sum
of 48 and - 19
We note that
19 in one’s complement 00010011
-19 in one’s complement is 11101100
26
One’s Complement
27
Two’s Complement
• To express a value in two’s complement:
– If the number is positive, just convert it to binary and you’re done.
– If the number is negative, find the one’s complement of the number
and then add 1.
• With two’s complement arithmetic, all we do is add our two
binary numbers. Just discard any carries emitting from the
high order bit.
Example One
– Using Two’s complement binary arithmetic, find the sum of
48 and - 19.
– 19 in one’s complement is 00010011
– -19 in one’s complement is 11101100
– -19 in two’s complement is 11101101
28
Overflow
29
Two’s Complement
Example Two
– Using two’s complement binary arithmetic, find the
sum of 107 and 46.
• We see that the nonzero carry from the seventh bit overflows into the
sign bit, giving us the erroneous result: 107 + 46 = -103
31
2.5 Floating-Point Representation
32
2.5 Floating-Point Representation
33
2.5 Floating-Point Representation
• Floating-point numbers allow an arbitrary number of decimal
places to the right of the decimal point.
– For example: 0.5 0.25 = 0.125
• They are often expressed in scientific notation.
– For example:
0.125 = 1.25 10-1
5,000,000 = 5.0 106
• Computers use a form of scientific notation for floating-
point representation
• Numbers written in scientific notation have three
components
34
2.5 Floating-Point Representation
• Computer representation of a floating-point number
consists of three fixed-size fields
36
2.5 Floating-Point Representation
37
2.5 Floating-Point Representation
38
2.5 Floating-Point Representation
39
2.5 Floating-Point Representation
• Example:
– Express 3210 in the revised 14-bit floating-point model.
• We know that 32 = 1.0 x 25 = 0.1 x 26.
• To use our excess 16 biased exponent, we add 16 to 6,
giving 2210 (=101102).
• Graphically:
40
2.5 Floating-Point Representation
• Example:
– Express 0.062510 in the revised 14-bit
floating-point model.
• We know that 0.0625 is 2-4. So in (binary) scientific notation 0.0625 = 1.0 x 2 -4 =
0.1 x 2 -3.
• To use our excess 16 biased exponent, we add 16 to -3, giving 13 10 (=011012).
41
Example
42
2.5 Floating-Point Representation
43
2.5 Floating-Point Representation
44
2.5 Floating-Point Representation
45
2.5 Floating-Point Representation
• Example:
– Find the sum of 1210 and 1.2510 using the 14-bit floating-point
model.
• We find 1210 = 0.1100 x 2 4. And 1.2510 = 0.101 x 2 1 =
0.000101 x 2 4.
• Thus, our sum is
0.110101 x 2 4.
46
2.5 Floating-Point Representation
47
2.5 Floating-Point Representation
• Example:
– Find the product of 1210 and 1.2510 using the 14-bit
floating-point model.
• We find 1210 = 0.1100 x 2 4. And 1.2510 = 0.101 x 2 1.
• Thus, our product is
0.0111100 x 2 5 =
0.1111 x 2 4.
• The normalized
product requires an
exponent of 2010 =
101102.
48
2.5 Floating-Point Representation
49
2.5 Floating-Point Representation
50
2.5 Floating-Point Representation
128.5 - 128
0.39%
128.5
• If we had a procedure that repetitively added 0.5 to
128.5, we would have an error of nearly 2% after only
four iterations.
51
2.5 Floating-Point Representation
52
2.5 Floating-Point Representation
53
2.5 Floating-Point Representation
54
2.5 Floating-Point Representation
55
2.5 Floating-Point Representation
56
2.6 Character Codes
57
Binary-Coded Decimal
• BCD is a numeric coding system used primarily in IBM
mainframe and midrange systems.
• As its name implies, BCD encodes each digit of a decimal
number to a 4-bit binary form.
• When stored in an 8-bit byte, the upper nibble is called the
zone and the lower part is called the digit.
• The high-order nibble in a BCD byte is used to hold the sign,
which can have one of three values
– An unsigned number is indicated with 1111
– a positive number is indicated with 1100
– a negative number is indicated with 1101
58
EXAMPLE Represent 1265 in 3 bytes using packed BCD.
The zoned-decimal coding for 1265 is:
1111 0001 1111 0010 1111 0110 1111 0101
After packing, this string becomes: 0001 0010 0110 0101
Adding the sign after the low-order digit and padding the high-order
digit with ones in 3 bytes we have
59
2.6 Character Codes
60
2.6 Character Codes
61
2.6 Character Codes
62
2.6 Character Codes
63
2.6 Character Codes
64
2.8 Error Detection and Correction
65
Error Detection and Correction
66
Error Detection and Correction
0+0=0 0+1=1
1+0=1 1+1=0
68
Error Detection and Correction
69
Error Detection and Correction
70
Error Detection and Correction
71
Error Detection and Correction
72
Error Detection and Correction
73
Error Detection and Correction
74
Error Detection and Correction
75
Error Detection and Correction
76
Error Detection and Correction
77
Error Detection and Correction
78
Error Detection and Correction
79
Error Detection and Correction
80
Error Detection and Correction
81
Error Detection and Correction
82
Error Detection and Correction
83
Error Detection and Correction
84
2.8 Error Detection and Correction
85
2.8 Error Detection and Correction
86
2.8 Error Detection and Correction
87