344-521 ก ˘ก ˇˇ ˆ˙˝˛ Computer Organization and Architecture

30
344-521 กก Computer Organization and Architecture Data Representation

Transcript of 344-521 ก ˘ก ˇˇ ˆ˙˝˛ Computer Organization and Architecture

344-521 ��� �ก������������ก ��������� �

Computer Organization and Architecture

Data Representation

���� 344-521 2

Character representation

� Each computer has a set of characters that it uses.

� Each character has been assigned a character code which is an unique integer.

� It is essential that communicating computers use the same code or they will not be able to understand one another.

� Therefore, standards have been developed :� EBCDIC� ASCII� Unicode

���� 344-521 3

Character representation (cont’d)

� EBCDIC stands for Extended Binary Coded Decimal Interchange Code. Developed by IBM for its mainframe computers.

� EBCDIC is an extension to 8 bits of BCDIC (BinaryCoded Decimal Interchange Code), an earlier 6-bit character set used on IBM computers.

� ASCII stands for American Standard Code for Information Interchange. It was developed so that computer systems made by a wide variety of different companies could exchange data with ease.

���� 344-521 4

Character representation (cont’d)

� ASCII uses only 7 bits, although these 7-bit characters are stored right-justified within standard 8-bit pattern.

� The eight bit of ASCII code can be used in one of two ways :� For character set expansion� For error checking

���� 344-521 5

Character representation (cont’d)

� Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language.

� The Unicode Standard has been adopted by such industry leaders as Apple, HP, IBM, JustSystem, Microsoft, Oracle, SAP, Sun, Sybase, Unisys and many others.

� Unicode is required by modern standards such as XML, Java, ECMAScript (JavaScript), LDAP, CORBA 3.0, WML, etc., and is the official way to implement ISO/IEC

10646. It is supported in many operating systems, all modern browsers, and many other products.

���� 344-521 6

Character representation (cont’d)

� Computers, like human beings, are inclined to make errors occasionally.

� A simple but widely used method for detecting single errors, that is, one bit changed from a 0 to a 1 or a1to a 0, is to add a parity bit to each character.

� In an odd-parity code, the parity bit chosen so that the number of 1 bit in the character, including the parity bit, is an odd number.

� In an even-parity code, the parity bit is chosen so that the number 1 bit in the character, including the parity bit, is an even number.

���� 344-521 7

Character representation (cont’d)

� Examples of 8- bit even–parity ASCII characters :

Parity 7-bit ASCII Characterbit character code 1 1 1 0 0 0 0 1 a

1 1 1 0 0 0 1 0 b 0 1 1 0 0 0 1 1 c 0 1 0 0 0 0 0 1 A 0 1 0 0 0 0 1 0 B

���� 344-521 8

Error-detecting and Error-Correcting Code

(cont’d)

� Simple parity allows detecting of single bit errors in a received message.

� Correction of such errors required more information to identifiy the position of the incorrect bit.

� If more bits are included with a message, and if those

bits can be arranged such that different errored bits produce different error results, then the incorrect bits could be identified.

� In a 4-bit message word, there are are four possible single bit errors so that the added three parity bits could

potentially specify not only that an error occurred but also which bit caused the error .

���� 344-521 9

Error-detecting and Error-Correcting Code

(cont’d)

� Consider the following even parity checking for data: 1110

1

10

1

0

0

0

3

6

57

2

1

4

���� 344-521 10

Error-detecting and Error-Correcting Code

� Parity bits are bit numbers that contain 20, 21, 22 � Parity bit numbers are 1, 2, 4� Bit numbers of data are 3, 5, 6, 7

Bit number 1 2 3 4 5 6 7

Data word 0 0 1 0 1 1 0

���� 344-521 11

Error-detecting and Error-Correcting Code

(cont’d)

� Suppose data is received later as 1100

1

10

0

0

1

1

3

6

5 7

21

4

Parity bit numbers are 1, 2, 4Data bit numbers are 3, 5, 6, 7

���� 344-521 12

Error-detecting and Error-Correcting Code

(cont’d)

Bit number 1 2 3 4 5 6 7

Data transmitted 0 0 1 0 1 1 0

Data recieved 0 1 1 1 1 0 0

Error 0 1 0 1 0 1 0

Thus error has occurred at bit number 2 + 4 = 6

���� 344-521 13

� A method for not detecting errors but for correcting them as well.

� Devised by Richard Hamming ( 1950 ) at Bell Laboratories.

� A Hamming code can be used on characters or messages or data of any length.

� In a Hamming code� k parity bits are added to an n-bit message (data) word on

the left forming a codeword of length k+n bits.� The bits are numbered starting at 1 (not 0) with bit 1 the

leftmost bit.� All bits whose bit number is a power of 2 are parity bits; the

rest are used for data.

Hamming code

���� 344-521 14

Hamming code (cont’d)

� Number of check bits for a message word that can correct a single error :

Message word size Parity bits needed Codeword size

4 3 (1, 2, 4) 7

8 4 (1, 2, 4, 8) 12

16 5 (1, 2, 4, 8, 16) 21

32 6 (1, 2, 4, 8, 16, 32) 38

���� 344-521 15

Hamming code (cont’d)

� k parity bits enable correction of a 1-bit error in a codeword that is 2k – 1 bits long (including the parity bits). Thus,

2k – 1 ≥ n + kwhere n is the message word size. This gives the number of bits needed to correct a single bit error in a word containing n data bits.

���� 344-521 16

Hamming code (cont’d)

� For a 4-bit message word :

� 3 parity bits are added to form 7-bit codeword.

� The bits 1, 2, and 4 are parity (check) bits.

� bits 3, 5, 6, and 7 are the 4 data bits.

� For a 8-bit message word :

� 4 parity bits are added to form 12-bit codeword.

� The bits 1, 2, 4, and 8 are parity (check) bits.

� bits 3, 5, 6, 7, 8, 9, 10, and 11 are the 8 data bits.

� For a 16-bit message word :

� 5 parity bits are added to form 21-bit codeword.

� The bits 1, 2, 4, and 8 are parity (check) bits.

� bits 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, and 15 are the 16 data bits.

���� 344-521 17

Hamming code (cont’d)

� For odd parity, the parity bit is set so that the total number of 1s in the checked position is odd.

� For even parity, the parity bit is set so that the total number of 1s in the checked position is even.

� Each parity bit checks specific bit positions.

���� 344-521 18

Hamming code (cont’d)

� Consider a message having four data bits (D) with three EVEN parity bits (P).

1

10

1

0

0

0

3

6

57

21

4

Bit 1 checks bits 1, 3, 5, 7Bit 2 checks bits 2, 3, 6, 7Bit 4 checks bits 4, 5, 6, 7

���� 344-521 19

Hamming code (cont’d)

� The parity of each parity bit is computed on different subsets of the codeword bits. For 4-bit data word :

Bit number 1 2 3 4 5 6 7

7-bit codeword P P D P D D D

Parity bit check position P - D - D - D

Parity bit check position - P D - - D D

Parity bit check position - - P D D D

���� 344-521 20

Hamming code (cont’d)

� The parity bit check position of 8 bits of data (8+4=12 bits codeword) :

Bit numerber 1 2 3 4 5 6 7 8 9 10 11 12

12-bit codeword P P D P D D D P D D D D

Parity bit check position P - D - D - D - D - D -

Parity bit check position - P D - - D D - D D -

Parity bit check position - - P D D D - - - - D

���� 344-521 21

Hamming code (cont’d)

� Bit 1 checks bits 1, 3, 5, 7 since bit postion 1, 3, 5, and 7 contain the term 20 (1 = 20 112 = 21+20 1012 = 22+20 1112 = 2

2+21+20)

� Bit 2 checks bits 2, 3, 6, 7 since bit postion 1, 3, 5, and 7 contain the term 21 (102=21+20 1012=22+20 1102=2

2+21 1112 = 22+21+20)

� Bit 4 check bits 4, 5, 6, 7 since bit postion 4, 5, 6, and 7 contain the term 22

� In general, bit n of a codeword is checked by those bits b1 , b2 , … , bj such that b1 + b2 + …+bj = n

���� 344-521 22

Hamming code (cont’d)

� Thus, for 4-bit message word with 3 checking bits � bit 1 is checked by bits 1 � bit 3 is checked by bits 1 and 2 because 1+2 = 3� bit 5 is checked by bits 1 and 4 because 1+4 = 5� bit 6 is checked by bits 2 and 4 because 2+4 = 6� bit 7 is checked by bits 1, 2 and 4 because 1+2+4=7

���� 344-521 23

Create a code word of a data word

� To create the code word of a data word as follows: � Mark all bit positions that are powers of two as parity bits.

(positions 1, 2, 4, 8, 16, 32, 64, etc.) � All other bit positions are for the data to be encoded. (positions

3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, etc.) � Each parity bit calculates the parity for some of the bits in the

code word. The position of the parity bit determines the sequence of bits that it alternately checks and skips.

� Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc. (1,3,5,7,9,11,13,15,...)

� Position 2: check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, etc. (2,3,6,7,10,11,14,15,...)

� Position 4: check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, etc. (4,5,6,7,12,13,14,15,20,21,22,23,...)

� etc.� Set a parity bit to

� 1 if the total number of ones in the positions it checks is odd. � 0 if the total number of ones in the positions it checks is even.

���� 344-521 24

Hamming Code

� For a data word of 8 bits with even parity will be arranged into a 12 bits codeword as :

Bit number 1 2 3 4 5 6 7 8 9 10 11 12

Code word C1 C2 D1 C4 D2 D3 D4 C8 D5 D6 D7 D8

The check bits are calculated as : C1 = D1 ⊕ D2 ⊕ D4 ⊕ D5 ⊕ D7

C2 = D1 ⊕ D3 ⊕ D4 ⊕ D6 ⊕ D7

C4 = D2 ⊕ D3 ⊕ D4 ⊕ D8

C8 = D5 ⊕ D6 ⊕ D7 ⊕ D8

���� 344-521 25

Hamming Code

� Assume that the transmitted data is 10011100, with data bit D1 in the leftmost position. ThusC1 = 1 ⊕ 0 ⊕ 1 ⊕ 1 ⊕ 0 = 1C2 = 1 ⊕ 0 ⊕ 1 ⊕ 1 ⊕ 0 = 1C4 = 0 ⊕ 0 ⊕ 1 ⊕ 0 = 1C8 = 1 ⊕ 1 ⊕ 0 ⊕ 0 = 0

� The corresponding codeword is

Bit number 1 2 3 4 5 6 7 8 9 10 11 12

Code word 1 1 1 1 0 0 1 0 1 1 0 0

���� 344-521 26

Hamming Code

� Suppose that data bit D3 sustains an error and is changed from 0 to 1and the received data becomes 10111100 . When the check bits are recalculated to getC1 = 1 ⊕ 0 ⊕ 1 ⊕ 1 ⊕ 0 = 1

C2 = 1 ⊕ 1 ⊕ 1 ⊕ 1 ⊕ 0 = 0

C4 = 0 ⊕ 1 ⊕ 1 ⊕ 0 = 0

C8 = 1 ⊕ 1 ⊕ 0 ⊕ 0 = 0

� The corresponding codeword is

Bit number 1 2 3 4 5 6 7 8 9 10 11 12

Code word 1 0 1 0 0 1 1 0 1 1 0 0

���� 344-521 27

Hamming Code

� When the new check bits are compared with the old check bits, the syndrome word is formed :

C8 C4 C2 C1 0 1 1 1

0 0 0 1

0 1 1 0

The result is 01102 = 4 + 2 = 6, indicates that bit number 6 of codeword contains data bit number 3 (D3), is in error.

���� 344-521 28

Hamming Code

� For a data word of 4 bits with even parity will be arranged into a 7-bit codeword as :

Bit number 1 2 3 4 5 6 7

Code word C1 C2 D1 C4 D2 D3 D4

The check bits are calculated as :C1 = D1 ⊕ D2 ⊕ D4 C2 = D1 ⊕ D3 ⊕ D4 C4 = D2 ⊕ D3 ⊕ D4

���� 344-521 29

Hamming Code

� Assume that the transmitted data is 1110, with data bit D1 in the leftmost position. ThusC1 = 1 ⊕ 1 ⊕ 0 = 0C2 = 1 ⊕ 1 ⊕ 0 = 0C4 = 1 ⊕ 1 ⊕ 0 = 0

� The corresponding codeword is

Bit number 1 2 3 4 5 6 7

Code word 0 0 1 0 1 1 0

���� 344-521 30

Hamming Code

� Suppose that data bit D3 sustains an error and is changed from 1 to 0 and the received data becomes 1100 . When the check bits are recalculated to getC1 = 1 ⊕ 1 ⊕ 0 = 0C2 = 1 ⊕ 0 ⊕ 0 = 1C4 = 1 ⊕ 0 ⊕ 0 = 1

� The corresponding codeword is

Bit number 1 2 3 4 5 6 7

Code word 0 1 1 1 1 0 0