lecture 6 topics –character codes binary-code decimal (bcd) extended binary coded decimal (ebcd)...

36
Lecture 6 Topics Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode Error Detection and Correction 1

Upload: abraham-hart

Post on 11-Jan-2016

259 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Lecture 6

• Topics– Character codes

• Binary-Code Decimal (BCD)• Extended Binary Coded Decimal (EBCD)• ASCII• Unicode

– Error Detection and Correction

1

Page 2: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

2

• Calculations aren’t useful until their results can be displayed in a manner that is meaningful to people.

• We also need to store the results of calculations, and provide a means for data input.

• Thus, human-understandable characters must be converted to computer-understandable bit patterns using some sort of character encoding scheme.

• Character code schemes– Binary-Code Decimal (BCD)– Extended Binary Coded Decimal (EBCD)– ASCII– Unicode

Character Codes

Page 3: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Binary Coded Decimal

• BCD encodes each digit of a decimal number into 4-bit binary form.

• Example: the decimal digits of 146 are encoded to 0001, 0100, 0110, respectively.

• Computers use bytes as the smallest unit of access, most values are stored in eight bits, not four. How to store BCD?

3

Page 4: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Warning: Conversion or Coding?• Do NOT mix up conversion of a decimal number to a binary

number with coding a decimal number with a binary code• Conversion:

– repeated division (multiplication) by 2 for integers (fractions)

• BCD coding: – Replacing each decimal digit of the number by its equivalent 4 bit BCD

code

• 1310 = (1101)2 This is conversion

• 13 (0001 0011)BCD This is coding

• In general, coding requires more bits than conversion• A number with decimal digits is coded with bits in BCD

Page 5: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Exercise

Convert into its binary equivalent value and give its BCD code as well.

Answer:

{ and }

Page 6: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

BCD-to-Decimal Conversion

Convert BCD code 1001 0100 0111 0000 to decimal

0000

0749

0100 01111001

Page 7: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Binary Coded Decimal (BCD)

• You can think of BCD in terms of column weights in groups of four bits. For an 8-bit BCD number, the column weights are: 80 40 20 10 8 4 2 1.

What are the column weights for the BCD number 1000 0011 0101 1001?

8000 4000 2000 1000 800 400 200 100 80 40 20 10 8 4 2 1

Note that you could add the column weights where there is a 1 to obtain the decimal number. For this case:

8000 + 200 +100 + 40 + 10 + 8 +1 = 835910

Page 8: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Binary Coded Decimal

• BCD storage– Unpacked BCD:

• padding the high-order nibbles with zeros or ones. – 146: 00000001 00000100 00000110

• wasteful

– Packed BCD: • stores two digits per byte• allows numbers to be signed, • the sign (unsigned, positive, or negative) is stored at

the end.– 146: 00010100 01101100

9

Page 9: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Binary Coded Decimal

• BCD storage (con’t)– Unpacked BCD: – Packed BCD: – Zoned decimal format of BCD:

• Similar to unpacked BCD, except padding with a specific pattern in the high-order nibbles, called zone.

• Allow signed numbers: sign is located in the high-order nibble of the least significant byte.

• Extended BCD Interchange Code (EBCDIC) zoned decimal format: pad the zone with all ones (hexadecimal F).

– 146: 11110001 11110100 11000110

• ASCII zoned decimal format: pad the zone with 0011 (hexadecimal 3).

– 146: 00110001 00110100 11000110

10

Page 10: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

BCD ExerciseRepresent 1265 using packed BCD and EBCDIC zoned decimal.

Solution:

The 4-bit BCD representation for 1265 is

0001 0010 0110 0101

Packed BCD: adding the sign after the low-order digit and padding the high-order bit with 0000,

00000001 00100110 01011101

EBCDIC zoned decimal: padding the high-order bits of the least significant byte with 1101 and padding the high-order bits of other bytes with 1111.

11110001 11110010 11110110 11010101

11

Page 11: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

12

• In 1964, BCD was extended to an 8-bit code, Extended Binary-Coded Decimal Interchange Code (EBCDIC).

• EBCDIC was one of the first widely-used computer codes that supported upper and lowercase alphabetic characters, in addition to special characters, such as punctuation and control characters.

• EBCDIC and BCD are still in use by IBM mainframes today.

EBCDIC

Page 12: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

EBCDIC

13

a: 1000 0001 A: 1100 0001 3: 1111 0011

Page 13: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

14

• Until recently, ASCII (American Standard Code for Information Interchange) was the dominant character code.

• ASCII: 1 high-order bit for parity, 7 bits for character codes.

• The parity bit is turned “on” or “off” depending on whether the sum of the other bits in the byte is even or odd.– “A”: lower 7 bits is 1000001, parity bit: 0; 0100 0001

– “C”: lower 7 bits is 1000011, parity bit: 1; 1100 0011

• Parity bit can be used to detect only single-bit errors.

• ASCII defines 32 control characters, 10 digits, 52 letters, 32 special characters.

ASCII

Page 14: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

ASCII

15

Page 15: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

16

• Both EBDIC and ASCII were built around the Latin alphabet and cannot provide data representation for the non-Latin alphabets.

• Many of today’s systems embrace Unicode, a 16-bit system that can encode the characters of every language in the world.

• The Unicode codespace is divided into six parts. The first part is for Western alphabet codes, including English, Greek, and Russian.

Unicode

CDA 3103 Computer Organization

Page 16: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

17

• The Unicode codes- pace allocation is shown at the right.

• The lowest-numbered Unicode characters comprise the ASCII code.

• The highest provide for user-defined codes.

Unicode

CDA 3103 Computer Organization

Page 17: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Parity Bit & Error Detection Codes• Binary data are typically transmitted between computers

• Because of noise, a corrupted bit will change value

• To detect errors, extra bits are added to each data value

• Parity bit: is used to make the number of 1’s odd or even

• Even parity: number of 1’s in the transmitted data is even

• Odd parity: number of 1’s in the transmitted data is odd

7-bit ASCII Character With Even Parity With Odd Parity

‘A’ = 1000001 0 1000001 1 1000001

‘T’ = 1010100 1 1010100 0 1010100

Page 18: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Detecting Errors

• Suppose we are transmitting 7-bit ASCII characters• A parity bit is added to each character to make it 8 bits• Parity can detect all single-bit errors

– If even parity is used and a single bit changes, it will change the parity to odd, which will be detected at the receiver end

– The receiver end can detect the error, but cannot correct it because it does not know which bit is erroneous

• Can also detect some multiple-bit errors– Error in an odd number of bits

Sender Receiver7-bit ASCII character + 1 Parity bit

Sent ‘A’ = 01000001, Received ‘A’ = 01000101

Page 19: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Exercise

Assign the proper even parity bit to the binary code 101101011111.

Answer: 1101101011111

An odd parity system receives the following code groups: 10110, 11010, 110011, 110101110100, and 1100010101010. Determine which groups, if any, are in error.

Answer: 110011, 1100010101010.

Page 20: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

21

• It is physically impossible for any data recording or transmission medium to be 100% perfect 100% of the time over its entire expected useful life.

• Thus, error detection and correction is critical to accurate data transmission, storage and retrieval.

• Check digits, appended to the end of a long number, can provide some protection against data input errors.

• Cyclic redundancy checking (CRC) codes provide error detection for large blocks of data.

Error Detection and Correction

Page 21: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

22

• Checksums and CRCs are examples of systematic error detection.

• In systematic error detection, a group of error control bits is appended to the end of the block of transmitted data.– This group of bits is called a syndrome.

• CRCs are polynomials over the modulo 2 arithmetic field.– In modulo 2 arithmetic if we add 1 to 1, we get 0. The addition

rules are:

0+0=0 0+1=1

1+0=0 1+1=0

The mathematical theory behind modulo 2 polynomials is beyond our scope. However, we can easily work with it without knowing its theoretical underpinnings.

Cyclic Redundancy Check

Page 22: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Modulo 2 division operates through a series of partial sums using the modulo 2 addition rules.

Example: Find the quotient and remainder when is divided by .

Modulo 2 Division

23The quotient is .

Page 23: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

24

Cyclic Redundancy Check

Sender side:1. Suppose we want to transmit the

information string: .2. The receiver and sender decide to use

the (arbitrary) polynomial pattern, 1101.3. The information string is shifted left by

one position less than the number of positions in the divisor.

4. The remainder is found through modulo 2 division (at right) and added to the Message : 1111101000 + 111 = .

Page 24: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

25

Receiver Side: is decoded and checked.• If no bits are lost or corrupted,

dividing the received information string by the agreed upon pattern will give a remainder of zero.

• A remainder other than zero indicates that an error has occurred in the transmission of .

Cyclic Redundancy Check

Page 25: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

26

• Hamming codes and Reed-Solomon codes are two important error correcting codes.

• Hamming codes, also called check bits or redundant bits, are an adaption of the concept of parity, whereby error detection and correction capabilities are increased in proportion to the number of parity bits added to an information word.

• Reed-Solomon codes are particularly useful in correcting burst errors that occur when a series of adjacent bits are damaged.– Because CD-ROMs are easily scratched, they employ a type of

Reed-Solomon error correction.

Error Correction

Page 26: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

27

• Hamming codes are code words formed by adding redundant check bits, or parity bits, to a data word.

• The Hamming distance between two code words is the number of bits in which two code words differ.

• The minimum Hamming distance for a code is the smallest Hamming distance between all pairs of words in the code.

• The minimum Hamming distance for a code, , determines its error detecting and error correcting capability.

This pair of bytes has a Hamming distance of 3:

Hamming Codes

Page 27: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

28

• For any code word, , to be interpreted as a different valid code word, , at least D(min) single-bit errors must occur in .

• Thus, to detect (or fewer) single-bit errors, the code must have a Hamming distance of .

• Hamming codes can detect D(min) - 1 errors and correct

errors.

• Thus, a Hamming distance of 2k + 1 is required to be able to correct k errors in any data word.

Hamming Codes

Page 28: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Hamming Codes• Assume a memory with 2 data bits and 1 parity bit • Even parity is used and the parity bit is appended at the

end of the code word. (so the number of 1s in the codeword must be even).

• The resulting code words have 3 bits. However, using 3 bits allows for 8 different bit patterns.

• Error correcting codes require more than a single parity bit.– If the code word 001 is encountered, it is invalid and thus indicates

an error. This error can be detected, but it cannot be corrected.

29

Page 29: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

30

• Suppose we have a set of n-bit code words consisting of m data bits and r (redundant) parity bits.

• Suppose also that we wish to detect and correct one single bit error only.

• An error could occur in any of the n bits, so each code word can be associated with n invalid code words at a distance of 1.

• Therefore, we have n + 1 bit patterns for each code word: one valid code word, and n invalid code words

Hamming Codes

Page 30: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

31

• Using bits, we have possible bit patterns. We have valid code words with check bits (where ).

• For each valid code word, we have bit patterns (1 legal and illegal).

• This gives us the inequality:

• Because , we can rewrite the inequality as:

or – This inequality gives us a lower limit on the number of check bits that

we need in our code words.

Hamming Codes

Page 31: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Hamming Codes

• Suppose we have data words of length . Then: implies that must be greater than or equal to 3.– This means to build a code with 4-bit data words that will correct

single-bit errors, we must add 3 check bits.

• Suppose we have data words of length m = 8. Then:

implies that must be greater than or equal to 4.– This means to build a code with 8-bit data words that will correct

single-bit errors, we must add 4 check bits, creating code words of length 12.

32

Page 32: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Hamming Algorithm

1. Determine the number of check bits, , necessary for the code and then number the bits (where ), right to left, starting with 1 (not 0)

2. Each bit whose bit number is a power of 2 is a parity bit—the others are data bits.

3. Assign parity bits to check bit positions as follows: Bit is checked by those parity bits such that . (Where “+” indicates the modulo 2 sum.)

33

Page 33: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

Hamming Codes – Example 1

Using the Hamming code and even parity, encode the 8-bit ASCII character K. (The high-order bit will be zero.) Induce a single-bit error and then indicate how to locate the error.

Solution:

Step 1: Determine the number of necessary check bits, add these bits to the data bits, and number all bits.

Because , we have , which implies must be greater than or equal to 4. We choose .

Step 2: Number the bits right to left, starting with 1, which results in:

The parity bits are marked with P.

34

Page 34: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

35

Step 3: Assign parity bits to check the various bit positons.

• First express all bits positions as sum of those numbers that are powers of 2:

– Bit 1 contributes to 1, 3, 5, 7, 9, 11.– Bit 2 contributes to the digits, 2, 3, 6, 7, 10, and 11.– Bit 4 provides parity for 4, 5, 6, 7, and 12– Bit 8 provides parity for 8, 9, 10, 11, 12.

• We can use this idea in the creation of our check bits.

Hamming Codes – Example 1

Page 35: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

36

• We can use this idea in the creation of our check bits.– Bit 1 contributes to 1, 3, 5, 7, 9, 11.– Bit 2 contributes to the digits, 2, 3, 6, 7, 10, and 11.– Bit 4 provides parity for 4, 5, 6, 7, and 12– Bit 8 provides parity for 8, 9, 10, 11, 12.

• The ASCII character for K is 01001011.• The code word for K is 010011010110

Hamming Codes – Example 1

Page 36: Lecture 6 Topics –Character codes Binary-Code Decimal (BCD) Extended Binary Coded Decimal (EBCD) ASCII Unicode –Error Detection and Correction 1

37

• Let introduce an error in bit position , resulting in the code word 010111010110.– Bit 1 checks 1, 3, 5, 7, 9, and 11: With even parity, this produces an

error.– Bit 2 checks 2, 3, 6, 7, 10, and 11: This is ok.– Bit 4 checks 4, 5, 6, 7, and 12: This is ok.– Bit 8 checks 8, 9, 10, 11, and 12: This produces an error.

• Parity bits 1 and 8 show errors. These two parity bits both check 9 and 11, so the single bit error must be in either bit 9 or bit 11.

• Since bit 2 checks bit 11 and indicates no error has occurred in the subset of bits it checks, the error must occur in bit 9.

Hamming Codes – Example 1