You are on page 1of 105

Chapter 3

Data Storage
&
Appendix H
Error Detection and Correction
Ting-Yi Chang
Professor
National Changhua University of Education, Taiwan, R.O.C.
Email: tychang@cc.ncue.edu.tw
Tel: 04-7232105 ext.7381

Modified from the instructor’s teaching material provided by


SOUTH-WESTERM CENGAGE LEARNING

Ch3-Storgae- 1
Outline
 Data types
 Error detection and correction (Appendix H)
 Storing numbers
 Storing text
 Storing audio
 Storing images
 Storing video

Ch3-Storgae- 2
Objectives

 List five different data types used in a computer.


 Error detection and correction (Appendix H)
 Describe how different data is stored inside a computer.
 Describe how integers are stored in a computer.
 Describe how reals are stored in a computer.
 Describe how text is stored in a computer using one of the
various encoding systems.
 Describe how audio is stored in a computer using sampling,
quantization and encoding.
 Describe how images are stored in a computer using raster
and vector graphics schemes.
 Describe how video is stored in a computer as a
representation of images changing in time.
Ch3-Storage- 3
3-1 INTRODUCTION

Data today comes in different forms including numbers, text,


audio, image and video (Figure 3.1).

Figure 3.1 Different types of data

The computer industry uses the term “multimedia” to define


information that contains numbers, text, images, audio and video.

Ch3-Storage- 4
Data inside the computer

All data types are transformed into a uniform


representation when they are stored in a computer and
transformed back to their original form when retrieved.
This universal representation is called a bit pattern (or
string of bits).

Figure 3.2 A bit pattern

Ch3-Storage- 5
Data inside the computer

Figure 3.3 Storage of different data types


Ch3-Storage- 6
Data compression

To occupy less memory space, data is normally


compressed before being stored in the computer. Data
compression is a very broad and involved subject, so we have
dedicated the whole of Chapter 15 to the subject.

Data compression is discussed in Chapter 15.

Ch3-Storage- 7
Error detection and correction

Another issue related to data is the detection and correction


of errors during transmission or storage. We discuss this
issue briefly in Appendix H.

Error detection and correction is discussed in Appendix H.

Ch3-Storage- 8
Appendix H

Error Detection and


Correction
Ting-Yi Chang
Professor
National Changhua University of Education, Taiwan, R.O.C.
Email: tychang@cc.ncue.edu.tw
Tel: 04-7232105 ext.7381

Modified from the instructor’s teaching material provided by


SOUTH-WESTERM CENGAGE LEARNING

Ch3-Storgae- 9
身分證字號產生規則
1. 台灣身分證字號共有十碼 , 我們就將它表示成 ... N1 N2 N3 N4 N5 N6 N7 N8 N9
N10
2. N1 : 一定是一個大寫英文字母 , 代表戶籍地 ex.A 是台北市 B 是台中市
A=10 B=11 C=12 D=13 E=14 F=15 G=16 H=17 J=18 K=19 L=20 M=21
N=22 P=23 Q=24 R=25 S=26 T=27 U=28 V=29 W=30 X=31 Y=32 Z=33
I=34 O=35
N1 ==>N1-1, N1-2
3. N2 : 性別欄位 : 1 為男性 2 為女性
4. N3 ~ N9 : 流水號
5. N10 : 檢測字元
6. 然後用下列算式計算 , 若餘數為 0 則為正確的身分證字號
(N1-1+N1-2×9+N2×8+N3×7+N4×6+N5×5+N6×4+N7×3+N8×2+N9+N10) mod 10 =
0

Example :
1. F212345674 換算為 15 212345674
2. (1×1)+(5×9)+(2×8)+(1×7)+(2×6)+(3×5)+(4×4)+(5×3)+(6×2)+(7×1)+(4×1)=150
3. 150 mod 10 = 0 => Correct

Ch3-Storage- 10
Error Detection and Correction (1/4)
• When data is transferred from one place to another, or moved
from one device to another, the accuracy of the data must be
checked.
• Some applications can tolerate a small level of error
– Random error in audio or video transmission
• Most applications such as text expect a very high level
accuracy

Ch3-Storage- 11
Error Detection and Correction (2/4)
• Interference ( 干擾 )
– Due to the crosstalk ( 線路干擾 ), external electromagnetic field ( 磁
場 ), and so on
• Single-bit error vs. burst error (two or more bits)
(See Figure H.1)

Ch3-Storage- 12
Error Detection and Correction (3/4)
• The central concept in correcting error is redundancy
– Send extra bits with our data
• Two main methods of error correction
– Forward error correction
• Receiver tries to guesses the message by using redundant bits
– Retransmission:
• The receiver detects the occurrence of an error and asks the
sender to resend the message

Ch3-Storage- 13
Error Detection and Correction (4/4)
• Redundancy is achieved through various coding schemes.
– The sender adds redundant bits through a process that create a
relationship between the redundant bits and the actual data bits
– The receiver check the relationships between the two sets of bits to
detect or correct the errors

Ch3-Storage- 14
Coding scheme
• We can divide coding scheme into two board categories:
– Block coding
– Convolution ( 迴旋 ) coding
• This book concentrate on block coding
– Convolution ( 迴旋 ) coding is more complex and beyond the scope of this
book
• Block coding
– Divide a message into blocks, each of k bits, called datawords.
– Then r redundant bits to each block are added to make the length n = k + r
– The resulting n-bits blocks are called codewords

Ch3-Storage- 14
Example H.2 Error detection

• The sender encodes the dataword 01 as 011 and sends it to the receiver
– If the receiver receives 011 the data is OK
– If the receiver receives 111  the data is corrupted
• However, if two bits is corrupted during transmission and 000 is
received
– The error can not be detected
– We need a better coding scheme
Ch3-Storage- 16
Example H.3 Error correction

• Error correction is more difficult than error detection


• Assume the dataword is 01 and the sender consults the table to create the
codeword 01011.
• Assume that only 1 bit is corrupted during the transmission and 01001
is received
– The receiver check the table and find the data is corrupted
– Correction: the receiver knows that the correct data should be 01011 since the
distance (number of different bits) between 01001 and 01011 is shortest (1).
– This approach is called Hamming code, which be will discussed later
Ch3-Storage- 17
H.3 Linear Block Codes

• Almost all block codes used today is linear block codes.


• The use of nonlinear block codes for error detection and
correction is not widespread
– They are harder to implement and analyze
• A linear block is a code in which the exclusive OR of two valid codewords creates
another valid codeword, see Table H.1 and Table H.2
• Some famous linear block codes
– Error detection:
• Parity bits (even versus odd) ( 同位位元 )
• Cyclic Redundancy Codes (CRC) ( 循環重覆碼 )
• Checksum ( 檢查和 )
– Error correcting
• Hamming code ( 漢明碼 )
Ch3-Storage- 18
Error detection:
Simple parity-check code
• Simple parity-check code (or called parity bit)
– Perhaps the most familiar error-detecting method
– k-bit dataword is coded to an k+1-bit codeword
– The extra bit is called parity bit ( 同位位元 )
• Even: the number of 1-bit is even (see 1)
– Limitation: only can detect odd-bit error

Ch3-Storage- 19
H.4 Error detection:
Cyclic Redundancy Codes (CRC)
- Widely used in networks such as WANs and LANs
- Approach:
– Message : M; Polynomial: P (predefined)
– Step 1: Compute M/P = Q(Quotient) … R(Remainder)
– Step 2: Transmit M || R
Remainder R is appended to the dataword M
- Example :
– Message : M= “1001” ; Polynomial P = “1011(x3+x+1)”
– Step 1: Compute 1001000/1011=1010…110 (assume codeword is 7-bit)
– Step 2: Transmit M || R= “1001110” (Q is discard and R is appended to M)
- The decoder dose the same division process, if Remainder is 0, it
means the received data is correct, otherwise the data is wrong.
- See Figures H.8 and H.9 in pages 578 and 579 for more details
- The performance of cyclic codes is good in detecting single-bit
errors, double errors, and burst errors.
Ch3-Storage- 20
Error detection:
Cyclic Redundancy Codes (CRC)

Ch3-Storage- 21
Error detection:
Cyclic Redundancy Codes (CRC)

Ch3-Storage- 22
Error detection:
Cyclic Redundancy Codes (CRC)

Ch3-Storage- 23
H.5 Error detection: Checksum
- Used in networks by several protocols
- Traditionally, the IP protocol has used a 16-bit checksum
- In addition to sending the numbers, we also send the sum of
them
– For example, if the set of numbers is (7, 11, 12, 0 , 6), we sent (7,
11, 12, 0 , 6, 36), where 36 is the sum of the original numbers
- Checksum is not as strong as the CRC in its error-checking
capacity.
– If the value of one word is incremented and the value of
another word is decremented by the same amount, the two
errors cannot be detected.
- See Example H.9 and Fig H.10 in pages 580 for more
details
Ch3-Storage- 24
Error Correction: Hamming Code

• Designed so that errors can be not only detected but also


corrected
• IEEE 802.11 無線網路協定及通用串行匯流排
( USB )協定,確保數據傳輸的可靠性。

Ch3-Storage- 25
Hamming code example:
1. 先取 R bits 的檢查碼: M +R+1≦ ,資料位元 M ,檢查
位元 R 。如 8 bits 資料,則 9+R≦ , R= 4 ,檢查位元為
4 bits 。則漢明碼編碼為 M + R = 8 + 4 = 12 bits 。
2. 編定位碼位置,並將資料位元填入;檢查位元以
C1 、 C2 、 C3 、…的順序,變成 C1() 、 C2() 、 C4() 、
C8() 、…的順序依須補在 P1 、 P2 、 P4 、 P8 、…的位
元位置。如下:
位元位置 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1
位置編碼 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001
資料位元 D8 D7 D6 D5 D4 D3 D2 D1
檢查位元 C8 C4 C2 C1

Ch3-Storage- 26
Hamming code example:
3. 以資料 1001,0110 為例。
位元位置 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1
位置編碼 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001
資料位元 1 0 0 1 0 1 1 0
檢查位元 C8 C4 C2 C1

Ch3-Storage- 27
Hamming code example:
4. 依照位元位置,如有資料位元有 1 者,將位置編碼填入相對位
置之下表:以 Cn 為行做偶同位。
編碼 檢查位元
位元位置 C8 C4 C2 C1
P1
P2
P3
P4
P5 0 1 0 1
P6 0 1 1 0
P7
P8
P9 1 0 0 1
P10

P11
P12 1 1 0 0
偶同位 0 1 1 0
Ch3-Storage- 28
Hamming code example:

5. 將完成的偶同位結果,回寫入上表的對應位置。
位元位置 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1
位置編碼 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001
資料位元 1 0 0 1 0 1 1 0
檢查位元 0 1 1 0

最後將得到的結果為 1001,0011,1010 ,既為漢明碼之編


碼。

Ch3-Storage- 29
Hamming code example:
1. 依照位元位置,如有資料位元有 1 者,將位置編碼填入相對位置之下表:
以 Cn 為行做 XOR 。若為 0000 表示正確。若使有數值,則表示該位元位
置的資料錯誤。
驗證 檢查位元
位元位置 C8 C4 C2 C1
P1
P2 0 0 1 0
P3
P4 0 1 0 0
P5 0 1 0 1
P6 0 1 1 0
P7
P8
P9 1 0 0 1
P10

P11
P12 1 1 0 0
偶同位 0 0 0 0 Ch3-Storage- 30
Hamming code example:
2. 假設 P5 有錯誤的漢明碼為 1001,0010,1010 ,如下做驗證:

位元位置 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1


位置編碼 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001
資料位元 1 0 0 1 0 1 0 0
檢查位元 0 1 1 0

Ch3-Storage- 31
Hamming code example:
驗證 檢查位元
位元位置 C8 C4 C2 C1
P1
P2 0 0 1 0
P3
P4 0 1 0 0
P5
P6 0 1 1 0
P7
P8
P9 1 0 0 1
P10
P11
P12 1 1 0 0
偶同位 0 1 0 1

經驗證,錯誤位置在 0101 ,位元位置 P5 的地方。


Ch3-Storage- 32
3-2 STORING NUMBERS
A number is changed to the binary before being stored in
the computer memory, as described in Chapter 2. However,
there are still two issues that need to be handled:
1. How to store the sign of the number.
2. How to show the decimal point.

1. Unsigned representation
2. Signed representation
(1) Sign-and-magnitude representation
(2) Two’s complement representation
(3) One’s complement representation

Ch3-Storage- 33
Storing integers
 Integers are whole numbers (numbers without a fractional
part). For example, 134 and −125 are integers, whereas
134.23 and −0.235 are not.
 An integer can be thought of as a number in which the
position of the decimal point is fixed:
 the decimal point is to the right of the least significant
(rightmost) bit.
 For this reason, fixed-point representation is used to store
an integer, as shown in Figure 3.4.
 In this representation the decimal point is assumed but not
stored.

Ch3-Storage- 34
Storing integers

Figure 3.4 Fixed point representation of integers

An integer is normally stored in memory using


fixed-point representation.

Ch3-Storage- 35
Storing integers: Unsigned representation

Unsigned representation

An unsigned integer is an integer that can never be negative


and can take only 0 or positive values. Its range is between 0
and positive infinity.
An input device stores an unsigned integer using the
following steps:
1. The integer is changed to binary.
2. If the number of bits is less than n, 0s are added to the
left.

Ch3-Storage- 36
Unsigned integer representation

Example 3.1
Store 7 in an 8-bit memory location using unsigned
representation.
Solution
First change the integer to binary, (111)2. Add five 0s to make a total of
eight bits, (00000111)2. The integer is stored in the memory location.
Note that the subscript 2 is used to emphasize that the integer is binary,
but the subscript is not stored in the computer.

Ch3-Storage- 37
Unsigned integer representation

Example 3.2

Store 258 in a 16-bit memory location.

Solution
First change the integer to binary (100000010)2. Add seven 0s to make
a total of sixteen bits, (0000000100000010)2. The integer is stored in
the memory location.

Ch3-Storage- 38
Unsigned integer representation

Example 3.3

What is returned from an output device when it retrieves the bit string
00101011 stored in memory as an unsigned integer?

Solution
Using the procedure shown in Chapter 2, the binary integer 00101011
is converted to the unsigned integer 43.

Ch3-Storage- 39
Unsigned integer representation
Figure 3.5 shows what happens if we try to store an integer
that is larger than 24 − 1 = 15 in a memory location that
can only hold four bits.

Figure 3.5 Overflow in unsigned integers


Ch3-Storage- 40
Unsigned integer representation
Unsigned integer representation can improve the efficiency
of storage because we do not need to store the sign of the
integer.
 Counting.
 Addressing.
 Storing other data types.

Ch3-Storage- 41
Sign-and-magnitude representation

In this method, the available range for unsigned integers (0


to 2n − 1) is divided into two equal sub-ranges. The first
half represents positive integers, the second half, negative
integers.

Figure 3.6 Sign-and-magnitude representation

In sign-and-magnitude representation, the leftmost bit


defines the sign of the integer. If it is 0, the integer is
positive. If it is 1, the integer is negative.
Ch3-Storage- 42
Sign-and-magnitude representation

Example 3.4

Store +28 in an 8-bit memory location using sign-and-magnitude


representation.

Solution
The integer is changed to 7-bit binary. The leftmost bit is set to 0.
The 8-bit number is stored.

Ch3-Storage- 43
Sign-and-magnitude representation

Example 3.5
Store -28 in an 8-bit memory location using sign-and-magnitude
representation.

Solution
The integer is changed to 7-bit binary. The leftmost bit is set to 1.
The 8-bit number is stored.

Ch3-Storage- 44
Sign-and-magnitude representation

Example 3.6
Retrieve the integer that is stored as 01001101 in sign-and-magnitude
representation.

Solution
Since the leftmost bit is 0, the sign is positive. The rest of the bits
(1001101) are changed to decimal as 77. After adding the sign, the
integer is +77

Ch3-Storage- 45
Sign-and-magnitude representation

Example 3.7

Retrieve the integer that is stored as 10100001 in sign-and-magnitude


representation.

Solution
Since the leftmost bit is 1, the sign is negative. The rest of the bits
(0100001) are changed to decimal as 33. After adding the sign, the
integer is −33.

Ch3-Storage- 46
Sign-and-magnitude representation

Figure 3.7 Overflow in sign-and-magnitude representation Ch3-Storage- 47


Two’s complement representation

 Almost all computers use two’s complement


representation to store a signed integer in an n-bit
memory location.

In this method, the available range for an unsigned integer


(0 to 2n − 1) is divided into two equal sub-ranges.
The first sub-range is used to represent nonnegative
integers
the second half to represent negative integers.
The bit patterns are then assigned to negative and
nonnegative (zero and positive) integers as shown in
Figure 3.8.
Ch3-Storage- 48
Two’s complement representation

Figure 3.8 Two’s complement representation


• In two’s complement representation, the leftmost bit defines the
sign of the integer. If it is 0, the integer is positive. If it is 1, the
integer is negative.
• There is only one zero in two’s complement notation.

別和 Sign-and-magnitude 搞混喔

Figure 3.6 Sign-and-magnitude representation Ch3-Storage- 46


One’s Complementing

Before we discuss Two’s complement representation further, we


first introduce one’s complementing (taking the one’s complement of
an integer). The operation can be applied to any integer, positive or
negative. This operation simply reverses (flips) each bit. A 0-bit is
changed to a 1-bit, a 1-bit is changed to a 0-bit.

Example 3.8
The following shows how we take the one’s complement of the
integer 00110110.

Ch3-Storage- 50
One’s Complementing

Example 3.9

The following shows that we get the original integer if we apply the
one’s complement operations twice.

Ch3-Storage- 51
Two’s Complementing

Two’s complementing
• This operation is done in two steps. First, we copy bits from the
right until a 1 is copied; then, we flip the rest of the bits
• 在不產生溢位的前提下,任一數字在進行二的補數運算後,會得到與其正
負號相反之值 (e.g., 6-6, -33)

An alternative way to take the two’s complement of an integer is to


first take the one’s complement and then add 1 to the result.
Example 3.10
Two’s Complementing

Example 3.11
The following shows that we always get the original integer if we
apply the two’s complement operation twice.

Ch3-Storage- 53
Two’s Complementing

Example 3.12

Store the integer 28 in an 8-bit memory location using two’s


complement representation.
Solution
The integer is positive (no sign means positive), so after
decimal to binary transformation no more action is needed.
Note that three extra 0s are added to the left of the integer to
make it eight bits.

Ch3-Storage- 54
Two’s Complementing

Example 3.13
Store −28 in an 8-bit memory location using two’s complement
representation.
Solution
The integer is negative, so after changing to binary, the computer
applies the two’s complement operation on the integer.

Ch3-Storage- 55
Two’s Complementing

Example 3.14
Retrieve the integer that is stored as 00001101 in memory in two’s
complement format.

Solution
The leftmost bit is 0, so the sign is positive. The integer is changed to
decimal and the sign is added.

Ch3-Storage- 56
Two’s Complementing

Example 3.15
Retrieve the integer that is stored as 11100110 in memory using two’s
complement format.
Solution
The leftmost bit is 1, so the integer is negative. The integer needs to
be two’s complemented before changing to decimal.

Ch3-Storage- 57
There is only one zero in two’s complement notation.

Figure 3.9 Overflow in two’s complement representation Ch3-Storage- 58


Why using two’s complement in
modern computer
• 二補數系統的最大優點是可以在加法或減法處理中,
不需因為數字的正負而使用不同的計算方式。只要
一種加法電路就可以處理各種有號數加法,而且減
法可以用一個數加上另一個數的二補數來表示 (a-b
= a+(-b), -b = b 的 1 補數 +1) ,因此只要有加法電
路及二補數電路即可完成各種有號數加法及減法,
在電路設計上相當方便。
• Want to know more about complement?
• See the Supplementary in the e-learning platform for the
details
Ch3-Storage- 59
Comparison for integers

Ch3-Storage- 60
Storing reals

A real is a number with an integral part and a fractional


part.
For example, 23.7 is a real number—the integral part is 23
and the fractional part is 7/10.
Although a fixed-point representation can be used to
represent a real number, the result may not be accurate
(the problem of accuracy(range)) or it may not have the
required precision (the problem of precision). The next
two examples explain why.
Real numbers with very large integral parts or very
small fractional parts should not be stored in fixed-
point representation.
Ch3-Storage- 61
Storing reals by fixed-point representation is
Unsuitable
Example 3.16 Precision problem
In the decimal system, assume that we use a fixed-point representation
with two digits at the right of the decimal point and fourteen digits at the
left of the decimal point, for a total of sixteen digits. The precision of a
real number in this system is lost if we try to represent a decimal number
such as 1.00234: the system stores the number as 1.00.

Example 3.17 Accuracy (range) problem


In the decimal system, assume that we use a fixed-point representation
with six digits to the right of the decimal point and ten digits for the left
of the decimal point, for a total of sixteen digits. The accuracy of a real
number in this system is lost if we try to represent a decimal number such
as 236154302345.00. The system stores the number as 6154302345.00:
the integral part is much smaller than it should be.
Ch3-Storage- 62
Floating-point representation

The solution for maintaining accuracy or precision is to use


floating-point representation.
Shift the decimal point

Figure 3.10 The three parts of a real number in floating-point representation

A floating point representation of a number is made up of three


parts: a sign, a shifter and a fixed-point number.

Ch3-Storage- 63
Floating-point representation:
scientific notation in decimal system
Example 3.18
The following shows the decimal number

7,452,000,000,000,000,000,000.00

in scientific notation (floating-point representation).

(7.425E21)

The three sections are the sign (+), the shifter (21) and the fixed-point
part (7.425). Note that the shifter is the exponent.

Ch3-Storage- 64
Floating-point representation:
scientific notation in binary system

Example 3.19
Show the number
−0.0000000000000232
in scientific notation (floating-point representation).
Solution

The three sections are the sign (-), the shifter (-14) and the fixed-point
part (2.32). Note that the shifter is the exponent.
Ch3-Storage- 65
Floating-point representation

Example 3.20
Show the number
(101001000000000000000000000000000.00)2
in floating-point representation.

Solution
We use the same idea, keeping only one digit to the left of the decimal
point.

Ch3-Storage- 66
Floating-point representation
Example 3.21
Show the number
−(0.00000000000000000000000101)2
in floating-point representation.

Solution
We use the same idea, keeping only one digit to the left of the decimal
point.

Ch3-Storage- 67
Normalization ( 正規化 )
• To make the fixed part of the representation uniform,
both the scientific method (for the decimal system) and
the floating-point method (for the binary system) use
only one non-zero digit on the left of the decimal
point. This is called normalization.
• In the decimal system this digit can be 1 to 9, while in the
binary system it can only be 1 (there are only 0 or 1 in
binary system). In the following, d is a non-zero digit, x
is a digit, and y is either 0 or 1.

Ch3-Storage- 68
Floating-point representation
After a binary number is normalized, only sign, exponent,
and mantissa ( 尾數 ) are stored

( 尾數 )
The shifting of the decimal point

• Note that the point and the bit 1 to the left of the fixed-
point section are not stored—they are implicit.
• The mantissa is a fractional part that, together with the
sign, is treated like an integer stored in sign-and-
magnitude representation. Ch3-Storage-69
Ch3-Storage- 69
Excess system for the exponent part

 The exponent that shows how many bits the decimal point should
be moved to the left or right, is a signed number
 Although this could have been stored using two’s complement
representation, a new representation, called the Excess system ( 超
碼系統,超值系統 ), is used instead.
 In the Excess system, both positive and negative integers are
stored as unsigned integers.
 To represent a positive or negative integer, a positive integer
(called a bias) is added to each number to shift them
uniformly to the non-negative side. The value of this bias is
2m−1 − 1, where m is the size of the memory location to store the
exponent.
 Why bias is 2m−1 − 1? See the next slide

Ch3-Storage- 70
Why bias in excess system is 2m−1 − 1 ?
Why bias is 2m−1 − 1 ? Remember that for m-bits excess system, the
smallest value is –(2m-1 − 1)(e.g. -7 in 4-bits). To make all values
positive, the bias should be 2m-1 − 1.

Figure 3.11 Shifting in Excess representation Ch3-Storage- 71

別把 Excess system 表示法和 two’s complement & Sing-and-magnitude 搞混喔


Excess-7

Example 3.22
We can express sixteen integers in a number system with 4-bit
allocation. By adding seven units to each integer in this range, we can
uniformly translate all integers to the right and make all of them
positive without changing the relative position of the integers with
respect to each other, as shown in the figure. The new system is
referred to as Excess-7, or biased representation with biasing value of 7.

Figure 3.11 Shifting in Excess representation Ch3-Storage- 72


Advantage of excess system

• All integers are positive and we don’t need to concerned


about the sign when we are comparing or doing operation
on the integers
• For example, when comparing two numbers, we can know
which number is larger by only comparing the exponent if
the two numbers have the same sign bit

Ch3-Storage- 73
IEEE Standard 754

Figure 3.12 IEEE standards for floating-point representation

Ch3-Storage- 74
IEEE specifications ( 規格單 ) 754

Ch3-Storage- 75
Example 3.23 Show the Excess_127 (single precision)
representation of the decimal number 5.75.
Solution
a. The sign is positive, so S = 0.
b. Decimal to binary transformation: 5.75 = (101.11)2.
c. Normalization: (101.11)2 = (1.0111)2 × 22.
d. E = 2 + 127 = 129 = (10000001)2, M = 0111. We need to add
nineteen zeros at the right of M to make it 23 bits.
e. The presentation is shown below:
0111

The number is stored in the computer as


01000000101110000000000000000000
Ch3-Storage- 76
Example 3.24
Show the Excess_127 (single precision)
representation of the decimal number –161.875.
Solution
a. The sign is negative, so S = 1.
b. Decimal to binary transformation: 161.875= (10100001.111)2.
c. Normalization: (10100001.111)2 = (1.0100001111)2 × 27.
d. E = 7 + 127 = 134 = (10000110)2 and M = (0100001111)2.
e. Representation:

The number is stored in the computer as


11000011001000011110000000000000

Ch3-Storage- 77
Example 3.25 Show the Excess_127 (single precision)
representation of the decimal number –0.0234375
Solution
a. S = 1 (the number is negative).
b. Decimal to binary transformation: 0.0234375 = (0.0000011)2.
c. Normalization: (0.0000011)2 = (1.1)2 × 2−6.
d. E = –6 + 127 = 121 = (01111001)2 and M = (1)2.
e. Representation:

The number is stored in the computer as

10111100110000000000000000000000

Ch3-Storage- 78
Example 3.26 The bit pattern (11001010000000000111000100001111)2 is
stored in Excess_127 format. Show the value in decimal.

Solution
a. The first bit represents S, the next eight bits, E and the remaining 23
bits, M.

b. The sign S is negative.


c. The shifter = E − 127 = 148 − 127 = 21.
d. This gives us (1.00000000111000100001111)2 × 221.
e. The binary number is (1000000001110001000011.11)2.
f. The absolute value is 2,104,378.75.
g. The number is −2,104,378.75.

Ch3-Storage- 79
3-3 STORING TEXT (1/3)

 A section of text in any language is a sequence of


symbols used to represent an idea in that language.

 For example, the English language uses 26 symbols (A,


B, C,…, Z) to represent uppercase letters, 26 symbols (a,
b, c, …, z) to represent lowercase letters, nine symbols (0,
1, 2, …, 9) to represent numeric characters and symbols (.,
?, :, ; , …, !) to represent punctuation.

 Other symbols such as blank, newline, and tab are used


for text alignment ( 組合 ) and readability.

Ch3-Storage- 80
STORING TEXT (2/3)

We can represent each symbol with a bit pattern. In other words, text
such as “CATS”, which is made up from four symbols, can be
represented as four n-bit patterns, each pattern defining a single
symbol (Figure 3.14).

Figure 3.14 Representing symbols using bit patterns

Ch3-Storage- 81
STORING TEXT (3/3)

Ch3-Storage- 82
Codes for storing text
 ASCII: Uses patterns of 7-bits to represent most symbols
used in written English text => Modified 8-bits
 Unicode: Uses patterns of 16-bits to represent the major
symbols used in languages world side.
32-bits now to represent most symbols used in
languages world wide
See the next slide for a detailed discussion of ASCII and
Unicode

ASCII table can be found in Table A.1 in p.501 in


Appendix A

Ch3-Storage- 83
ASCII (America Standard Code for Information
Interchange) 美國資訊交換標準碼
• ASCII ,鑑於資訊交換的重要及為統一文字符號的編碼標準,讓不
同廠牌機型的電腦皆能使用同一套標準化的資訊交換碼,於是美國
國家標準局特別制定了 ASCII 碼,作為資料傳輸的標準碼。
• 早期使用 7 個位元來表示英文字母、數字 0~9 及其他符號,現在
則使用 8 個位元 (Extended ASCII) ,共可表示 256 個不同的文字
與符號,為目前各電腦系統中使用最普遍也最廣泛的英文標準碼,
• 相對於 ASCII code ,中文系統使用最廣泛的內碼則為 Big-5 碼。
• 另外由數家知名軟硬體廠商所合作發展的萬國碼 (UNICODE) ,則
是資料表示的新標準, UNICODE 使用 2 或 4 個 bytes(16 or 32
bits) 來表示每一個符號,共可表示 65536 個或 1677 萬個字元符
號,除英文外,還可以包含數量最多的中文、日文,及全世界各國
的文字符號,讓資訊之交流更無國界。 (Windows98 已開始支援
UNICODE)

Ch3-Storage- 84
Extended ASCII Table (8bits)
85

Ch3-Storage- 81
86
87
Representing Text – Unicode
http://www.unicode.org/

Ch3-Storage- 88
3-4 STORING AUDIO

Audio is a representation of sound or music. Audio is


different to the numbers or text we have discussed so far.
• Text is composed of countable entities (characters):
we can count the number of characters in text.
• By contrast, audio is not countable
• Text is an example of digital data ( 數位資料 ). Audio
is an example of analog data ( 類比資料 ).
• Even if we are able to 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.
Ch3-Storage- 89
數位訊號 vs. 類比訊號

 類比訊號分為無線類比訊號及有線類比訊號兩種,早期第四台業
者不發達的情況下,大部分的家庭都是收無線台(台視、中視、
華視),後來慢慢的家家戶戶都裝了第四台的有線類比訊號,不
僅節目多元化、收訊品質也比無線好上許多
 視訊壓縮技術之進步,因此可將類比的畫面信號經數位化處理後,
變成一串數據資料 ( 數位訊號 ) ,亦即只有 0 與 1 兩個數字組成
的「二進位」型式訊號 ( 類似電腦系統中資料處理之訊號 )
 透過數位訊號處理,可以消除雜訊和干擾,畫面將會更清、
細 致 , 同 時 也 提 供 身 歷 聲 ( 杜 比 AC3) 品 質 效 果 ,
再經數位調變傳送到家,因此可獲得比原來的類比電視更好
的影像及聲音品質,
 因為數位訊號的特性關係,收訊將會比類比訊號要來的容易,
不需要調整半天
Ch3-Storage- 90
An audio signal

• Figure 3.15 shows the nature of an analog signal, such as


audio, that varies with time.

Ch3-Storage- 91
Storing audio: Sampling

If we cannot record all the values of a an audio signal


over an interval, we can record some of them.
Sampling ( 取 樣 ) means that we select only a finite
number of points on the analog signal, measure their
values, and record them.

Figure 3.16 Sampling an audio signal


Ch3-Storage- 92
Storing audio: Quantization ( 量化 )

The value measured for each sample is a real number. It


has been shown that a sampling rate of 40,000 samples
per second is good enough to reproduce an audio signal.
This means that we can store 40,000 real values for each
one second sample. However, it is simpler to use an
unsigned integer (a bit pattern) for each sample.
• Quantization refers to a process that rounds the value of
a sample to the closest integer value. For example, if the
real value is 17.2, it can be rounded down to 17: if the
value is 17.7, it can be rounded up to 18.

Ch3-Storage- 93
Encoding

The next task is encoding. The quantized sample values need to be


encoded as bit patterns.
Some systems assign positive and negative values to samples, some
just shift the curve to the positive part and assign only positive
values.
In the past only 8 bits were assigned to sound samples, today 16, 24, or
even 32 bits per sample is normal. The number of bits per sample is
sometimes referred to as the bit depth B
 Suppose the number of samples per second S, we need to store S × B
bits for each second of audio.
 This product is sometimes referred to as bit rate( 位元率 ), R (= S × B).
 For example, if we use 40,000 samples per second and 16 bits per
each sample, the bit rate is R = 40,000 × 16 = 640,000 bits per second
Ch3-Storage- 94
MP3 : Standards for sound encoding

 Today the dominant standard for storing audio is MP3 (short for
MPEG Layer 3).
 This standard is a modification of the MPEG (Motion Picture
Experts Group) compression method used for video.
 It uses 44100 samples per second (44.1KHz) and 16 bits per
sample.
 The result is a signal with a bit rate of 705,600 bits (about 86KB)
per second, which is compressed using a compression method that
discards information that cannot be detected by the human ear.
This is called lossy compression ( 失 真 壓 縮 ), as opposed to
lossless compression (more about compression is discussed in
Chapter 15.)

Ch3-Storage- 95
Musical CD

• Musical CD
– Sampling rate 44,100 samples per second
– Each sample is 16 bits (32 bits for stereo)
– Each second of music recorded in stereo requires 44100*32 =
1,411,200 bits

Ch3-Storage- 96
3-5 STORING IMAGES

Color depth
 The number of bits used to represent a pixel, its color
depth, depends on how the pixel’s color is handled by
different encoding techniques.
 The perception of color is how our eyes respond to a beam
of light ( 光束 ).
 Our eyes have different types of photoreceptor cells ( 視感
神經細胞 ): some respond to the three primary colors red,
green and blue (often called RGB), while others merely
respond to the intensity ( 強度 ) of light.

Ch3-Storage- 97
True-Color ( 全彩 )

One of the techniques used to encode a pixel is called True-


Color, which uses 24 bits (about 16 million colors) to
encode a pixel.

Ch3-Storage- 98
 一般「解析度」,指的是 50 * 50 px 這樣寬 × 高的表達方式,解析度一般
會用來表示圖片、螢幕的寬、高畫素數,例如 1920 * 1080 px 的螢幕,如
果把時間往回推三十年,當時的螢幕解析度只有 640 * 480 px 或更低,在
當時的螢幕上,像素點是清晰可見的,但數位可以放大或縮小:

Ch3-Storage- 99
 同樣是 15 英吋大小的螢幕,一個的解析度是超古老的 640 * 480 px ,另一
個是 1,920 * 1,440 px ,兩者的 X 、 Y 方向的像素數各差了三倍,這之間
的差異可以用不同年代的同一款遊戲的畫面來感受。

Ch3-Storage- 100
 ​解析度 (resolution) ,單位長度內像素的數量。解析度採用的長度單位是
英寸 (inch) 。解析度嚴格來說又可以分為 ppi 與 dpi : ppi 為影像解析度
(pixels per inch) 、 dpi 為輸出解析度 (dots per inch) 。 pixel 是數位影像的
像素,而 dot 是列印成品的圖點。

Ch3-Storage- 101
 在 2010 年發佈 iPhone4 的時候, Jobs 說明當你拿着手機距離 10-12 英吋
時, 326 的 ppi 是我們肉眼能分辨像素的極限。也就是滿足 326ppi 觀屏距
離 10-12 英寸時,人眼察覺不出大於 326ppi ?

Ch3-Storage- 102
Digital Camera
 2,500 像素,指的是像素的總數量,一般會用來表示相片或相機感光元件的像
素數量,例如一張 2,500 像素的相片,或者一台百萬像素的相機,而「百萬像
素」( mega pixel )又被縮寫成 MP ,所以 iPhone 的相機是 12MP ,意即
iPhone 的感光元件的有效面積大約是一千兩百萬像素,在不裁切或縮放的情況
下它可以輸出 4,032 * 3,024 ≈ 1,200 萬像素的照片。

Ch3-Storage- 103
Standards for image encoding

 JPEG (Joint Photographic Experts Group) uses the


True-Color scheme, but compresses the image to reduce
the number of bits (see Chapter 09).

Ch3-Storage- 104
3-6 STORING VIDEO
Video is a representation of images (called frames) over
time. A movie consists of a series of frames shown one after
another.
In other words, video is the representation of information
that changes in space and in time.
So, if we know how to store an image inside a computer,
we also know how to store video: each image or frame is
transformed into a set of bit patterns and stored. The
combination of the images then represents the video.

Ch3-Storage- 105

You might also like