COS1521-foundations_of_computer_science_-chapter_3
COS1521-foundations_of_computer_science_-chapter_3
Second Edition
BEHROUZ FOROUZAN
FIROUZ MOSHARRAF
Chapter 3
Data Storage
1
Outlines
z Data Types
z Storing numbers
z Storing text
z Storing audio
z Storing images
z Storing video
2 CSIM@PU
Objectives
4
Introduction
6
7 Figure 3.3 Storage of different data types
Data compression &
Error detection and correction
z Data compression
– To occupy less memory space, data is normally
compressed before being stored in the computer.
– Details in Chapter 15.
z Error detection and correction
– Another issue related to data is the detection and
correction of errors during transmission or
storage.
– Briefly in Appendix H.
8
3.2 Storing Numbers
9
Overview
10 CSIM@PU
Storing Integers
12
Unsigned representation (2)
z Example 3.3
– What is returned when retrieving the bit string 00101011
stored in memory as an unsigned integer?
– The binary integer is converted to the unsigned integer 43.
14
Unsigned representation (4)
15
Sign-and-magnitude
representation (1)
17
Sign-and-magnitude
representation (3)
18
Sign-and-magnitude
representation (4)
21
Two’s complement representation (2)
23
One’s Complementing (2)
24
Two’s Complementing (1)
25
Two’s Complementing (2)
27
z Example 3.14 retrieves the integer that is stored as
00001101 in memory in two’s complement format.
28
Two’s Complementing (4)
Overflow
30
Storing Reals (1)
33
Floating-point representation (2)
34
Floating-point representation (3)
35
Floating-point representation (4)
36
Normalization (1)
37
Normalization (2)
z Note that the point and the bit 1 to the left of the
fixed-point section are not stored—they are implicit.
z The mantissa is a fractional part that, together with
the sign, is treated like an integer stored in sign-and-
magnitude representation.
38
Excess System (1)
z Exponent
– To show how many bits the decimal point should be moved to the
left or right.
– Being a signed number (使用Excess system)
z Excess System
– Positive and negative integers are stored as unsigned integers.
– A positive integer (called a bias) is added to each number to shift
them uniformly to the non-negative side.
z The value of this bias is 2m-1 − 1, where m is the size of the
memory location to store the exponent.
39
Excess System (2)
40
41
IEEE Standard
43
Excess System Example (1)
Solution
• The first bit is S, the next eight bits, E and the remaining 23 bits, M.
b. The shifter = E − 127 = 148 − 127 = 21.
c. This gives us (1.00000000111000100001111)2 × 221.
d. The binary number is (1000000001110001000011.11)2.
e. The absolute value is 2,104,378.75.
47 f. The number is −2,104,378.75.
Overflow and Underflow
48
Storing Zero
49
3.3 Storing Text
50
Overview (1)
51
Overview (2)
53
Overview (4)
54
3.4 Storing Audio
55
Overview (1)
z Audio
– A representation of sound or music.
– Different to the numbers or text.
z Text is composed of countable entities
(characters); Text is an example of digital data.
– Being not countable.
– An example of analog data.
z Even if we can measure all its values in a period of time, we
cannot store these in the computer’s memory, as we would
need an infinite number of memory locations.
z How to store audio data
56 – Sampling Æ Quantization Æ Encoding
Overview (2)
57
Sampling
59
Encoding
62
Overview (1)
65
Indexed Color (Palette color) (1)
67
Standards for image encoding
70
Overview
72
r’s Complement
z 若一無號的數字N(N ≠ 0),基底(base)是r,
整數部分的位數為n,則它的r’s complement
定義為(rn − N),且令N = 0時,N的r補數為0。
舉例說明如下:
73
(r – 1)’s Complement
z 若一無號的數字N(N ≠ 0),基底(base)是r
,整數部分的位數為n,則它的(r−1)補數為(rn
− 1) − N,且令N = 0時,N的(r−1)補數為0。
舉例說明如下:
74
IEEE 754
Excess 127
single precision
75
IEEE 754
z 小數部分最高有效位由exp部分決定。如果指
數在0 < exponent < 2e − 1之間,那麼小數部
分最高有效位將是1,而且這個數將被稱為正
規形式。
z 如果exp是0,有效數最高有效位將會是0,並
且這個數將被稱為非正規形式。
z 有三個特殊值需要指出:
76
IEEE 754
77
IEEE 754
78