Post on 21-Mar-2020
Digital Circuit And Logic Design I
Lecture 2
Panupong Sornkhom, 2005/2 2
Outline
Number System and Codes (2)1. Codes2. Error detecting and correcting
Number System and Codes (2)
Panupong Sornkhom, 2005/2 4
1. Codes
What is codeDecimal number codesGray codeCharacter codesCode for action, condition and states
Panupong Sornkhom, 2005/2 5
What is code?
A digital system requires that all information be in binary form.The external world, however, uses various other symbols to represent information.A symbol is represented in a digital system by a string of bitsA set of n-bit strings in which different bit strings represent different symbol is called a code.A particular pattern of string is called code word.
Panupong Sornkhom, 2005/2 6
Decimal number codes
Binary-Coded Decimal (BCD) code
Encode the digit 0 – 9 by their 4-bit unsigned binary representation, other code word are not usedBCD is a weighted code, the weight are 8,4,2,1. so, sometime this code called 8421 code.
2421 codeWeighted code with self-complementing (9’s complement)
Excess 3 codeSelf-complementing but is not weighted codeExcess3 = BCD + 00112
Biquinary codeUses 7 bits per code wordThe first two bits indicate range of number 0-4 or 5-9, and the last five bits indicate which of the five numbers in the selected range is represented
1-out-of-10 codeUsing 10-bit code word.
Panupong Sornkhom, 2005/2 7
Decimal codes
000000000110100001111111110019000000001010010001011111010008000000010010001001010110101117000000100010000101001110001106000001000010000011000101101015000010000001100000111010001004000100000001010000110001100113001000000001001000101001000102010000000001000100100000100011100000000001000010011000000000
1-out-of-10BiquinaryExcess-32421BCD(8421)
Decimal digit
Panupong Sornkhom, 2005/2 8
Gray code
It is sometimes necessary for an input sensor to produce a digital value that indicates a mechanical position.The encoder has a problem when the disk is positioned at certain boundaries between the regions where more than one bit changesThis problem can be solved by devising a digital code in which only one bit changes between each pair of successive code words. Such a code is called Gray code
3-bit binary code
3-bit Gray code
Panupong Sornkhom, 2005/2 9
Gray code (cont.)
There are two convenient ways to construct n-bit Gray code
The first method is based on the fact that Gray code is a reflected code
A 1-bit Gray code has two code words, 0 and 1.The first 2n code words of an (n+1)-bit Gray code equal the code words of an n-bit Gray code, written in order with a leading 0 appendThe last 2n code words of an (n+1)-bit Gray code equal the code words of an n-bit Gray code, written in reverse order with a leading 1 append 100--7
101--6
111--5
110--4
01010-3
01111-2
0010111
0000000
3 bits2 bits1 bitDecimal
Panupong Sornkhom, 2005/2 10
Gray code (cont.)
The second method allows us to derive n-bit Gray-code code word directly from the corresponding n-bit binary code word
The bits of an n-bit binary or Gray-code code word are numbered from right to left, from 0 to n-1Bit i of a Gray-code code word is 0 if bits i and i+1 of the corresponding binary code word are the same, else bit i is 1. (When i+1 = n, bit n of the binary code word is considered to be 0.) 1001117
1011106
1111015
1101004
0100113
0110102
0010011
0000000
Gray codeBinary codeDecimal number
Panupong Sornkhom, 2005/2 11
Character codes
The most commonly used character code is ASCII, the American Standard Code for Information Interchange.ASCII represents each character with a 8-bit string, in fact 7 bits are sufficient for EnglishThe code contains the uppercase and lowercase alphabet, numerals, punctuation, and various nonprinting control characters.
Panupong Sornkhom, 2005/2 12
Character codes (cont.)
Pictures from http://www.jimprice.com/jim-asc.htm
Panupong Sornkhom, 2005/2 13
Character codes (cont.)
Pictures from http://www.jimprice.com/jim-asc.htm
Panupong Sornkhom, 2005/2 14
Codes for Actions, Conditions, and States
Characters and numbers are considered to be data but sometimes we need non-data codes to represent actions, conditions, or states.For example, consider a simple traffic-light controller.
110ONOFFOFFONOFFOFFE-W delay
101OFFONOFFONOFFOFFE-W wait
100OFFOFFONONOFFOFFE-W go
010ONOFFOFFONOFFOFFN-S delay
001ONOFFOFFOFFONOFFN-S wait
000ONOFFOFFOFFOFFONN-S go
Code wordE-W Red
E-W YellowE-W GreenN-S Red
N-S YellowN-S Green
LightsState
Panupong Sornkhom, 2005/2 15
2. Error detecting and correcting
IntroductionSingle error detectingError correcting and multiple errors detectingHamming code
Panupong Sornkhom, 2005/2 16
Introduction
An error in a digital system is the corruption of the data from its correct value to some other value caused by physical failureFailure can be either temporary or permanentSingle error = failure affect only a single bit of dataMultiple errors = two or more bits in errorError-detecting codes
A code that uses n-bit strings need not contain 2n valid code wordsCorrupting a code word will likely produce a bit string that is not a code word
Panupong Sornkhom, 2005/2 17
Single error detecting
A code detects all single errors is the minimum distancebetween all possible pairs of code words is 2In general, we need n+1 bits to construct a single-error-detecting code with 2n code words.
The first n bits of a code word = information bitsThe last one bit = parity bit
111 0111 1111
110 1110 0110
101 1101 0101
100 0100 1100
011 1011 0011
010 0010 1010
001 0001 1001
000 1000 0000
Odd-parity code
Even-parity code
Information bits
Panupong Sornkhom, 2005/2 18
Error-correcting and multiple-error-detecting codes
Assume that failures affect at most one bit of each code word, then a noncode word with a 1-bit error will be closer to the originally code word than to any other code word.Therefore, we can correct the error by changing the noncode word to the nearest code wordA code that is used to correct errors is called an error-correcting codeIf a code has minimum distance 2c+1, it can be used to correct errors that affect up to c bitsIf a code’s minimum distance is 2c+d+1, it can be used to correct errors in put to c bits and to detect errors in put to d additional bits
Panupong Sornkhom, 2005/2 19
Error-correcting and multiple-error-detecting codes (cont.)
For example, a code with minimum distance 4 (c=1, d=1)
Single-bit errors that produce noncode words 00101010 and 11010011 can be correctedHowever, a error that produces 10100011 can’t be corrected but can be detected
Pictures from Textbook DDPP
Panupong Sornkhom, 2005/2 20
Error-correcting and multiple-error-detecting codes (cont.)
A 3-bit error may be “corrected” to the wrong value. It may be acceptable if 3-bit errors are rarely to occur. However, if we concerned about 3-bit errors, we can change the decoding policy for the code by just flag all noncode words as uncorrectable errors.
Picture from Textbook DDPP
Panupong Sornkhom, 2005/2 21
Hamming codes
In 1950, R. W. Hamming described a general method for constructing codes with a minimum distance of 3, now called Hamming codesFor any value of i, his method yields a (2i – 1)-bit code (check bits = i bits and information bits = 2i – 1 – i bits)The bit positions can be numbered from 1 through 2i-1.
Any position whose number is power of 2 is a check bitThe remaining positions are information bits
Panupong Sornkhom, 2005/2 22
Hamming codes (cont.)
Each check bit is grouped with a subset of the information bits, as specified by a parity-check matrix.
Each check bit is grouped with the information positions whose numbers have a 1 in the same bit when expressed in binaryFor example, check bit 2 (010) is grouped with information bits 3 (011), 6 (110), and 7 (111)
For a given combination of information-bit values, each check bit is chosen to produce even parity, so the total number of 1s in its group is even.
Panupong Sornkhom, 2005/2 23
Hamming codes (cont.)Parity-check matrices for 7-bit Hamming codes:
(a) With bit positions in numerical order;
(b) With check bits and information bits separated
Panupong Sornkhom, 2005/2 24
Hamming codes (cont.)
ExampleDistance-3 Hamming code
Information bits = 0000 Parity bits = 000Information bits = 0100 Parity bits = 110Information bits = 0111 Parity bits = 000Information bits = 1100 Parity bits = 001Information bits = 1101 Parity bits = 010
A distance-3 Hamming code can easily be modified to increase its minimum distance to 4.
By adding one more check bit, chosen that the parity of all the bits is even.
Panupong Sornkhom, 2005/2 25
CRC codes
CRC stands for Cyclic-redundancy-checkTwo important applications of CRC codes are in disk drives and in data networks.
In a disk drive, each block of data (typically 512 bytes) is protected by a CRC codeIn a data network, each packet of data ends with check bits in a CRC code
The CRC codes for both applications were selected because of their burst-error detecting properties. Such errors are more likely than errors of randomly distributed bits, because of the likely physical causes of errors in the two applications – surface defects in disk drives and noise bursts in communication links.
Panupong Sornkhom, 2005/2 26
Checksum codes
Using technique of modular additionFor example
A computer stores information as a set of 8-bit bytes.Each byte may be considered to have a decimal value from 0 to 255.Therefore, we can use module-256 addition to check the bytes.We form a single check byte called, checksum, that is the sum ofmodule256 of all the information bytes. The resulting checksum code can detect any single byte error, since such error will cause a recomputed sum of bytes to disagree with the checksum.
Checksum codes can also use a different modulus of addition.
Panupong Sornkhom, 2005/2 27
Two-Dimensional codes
It is another way to obtain a code with large minimum distanceThe information bits are conceptually arranged in a two-dimensional array, and parity bits are provided to check both the rows and the columns.A code Crow with minimum distance drow is used for the rows, and a possibly differrent code Ccol with minimum distance dcol is used for the columns.The row-parity bits are selected so that each row is a code word in Crow and the column-parity bits are selected so that is a code word in Ccol
The “corner” parity bits can be chosen according to either code.The minimum distance of the two-dimensional code is the product of drow and dcol; in fact, two-dimensional codes are sometimes called product codes
Panupong Sornkhom, 2005/2 28
Two-Dimensional codes (con.)
Pictures from Textbook DDPP