Vous êtes sur la page 1sur 78

Ch. 2.

Number Systems & Codes


Positional notation Nonpositional notation Decimal numbers Binary numbers Octal numbers Hexadecimal numbers Base conversions Fractional Numbers Arithmetic (addition, subtraction, multiplication, division) Complement of binary numbers Signed number representation Binary coded decimal (BCD) Computer codes Error detection

Positional Notation
Consider a typical decimal number 872.64 = 800 + 70 + 2 + 0.6 + 0.04 = 8 102 + 7 101 + 2 100 + 6 10-1 + 4 10-2 Each symbol (8,7,2,6, or 4) in 872.64 is called digit and represents a nonnegative integer quantity. Weighting factor (i.e.. 102, 101, etc.) is totally determined by the location of the symbol within the number. Decimal number system is an example of positional number system. The distinct digits (i.e.. 0,1,,9) in the number system defines the base or radix of the number system. Radix point a delimiter used to separate the integer and fraction parts of the number (decimal point). 8 Most Significant Digit (MSD); 2 - Least Significant Digit (LSD).

Cont
Some examples of positional number systems: Base 2 3 4 5 8 10 12 16 Number System Binary Ternary Quaternary Quinary Octal Decimal Duodecimal Hexadecimal Digit symbols 0,1 0,1,2 0,1,2,3 0,1,2,3,4 0,1,2,3,4,5,6,7 0,1,2,3,4,5,6,7,8,9 0,1,2,3,4,5,6,7,8,9,A,B 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

Cont
The weighting structures of number systems Decimal number 10n-1103 102 101100.10-1 10-2 10-310-n Decimal point Binary number 2n-123 22 2120.2-1 2-2 2-32-n Binary point Octal number 8n-183 82 8180.8-1 8-2 8-38-n Octal point Hexadecimal number 16n-1163 162 161160.16-1 16-2 16-316-n Hexadecimal point

Nonpositional Notation
In nonpositional number system, the relative location of a symbol in the number plays a minimal role in determining the total quantity being represented. Many different symbols are used and each having a fixed definite quantity associated with it. Example of are text, marks, and roman numbers.

Cont
Text:
one two three four five six seven eight nine ten

Cont
Marks:
| || ||| |||| |||| |||| | |||| || |||| ||| |||| |||| |||| ||||

Cont
Roman numbers:
I II III IIII V VI VII VIII VIIII X

Decimal Numbers
Arabic numbers: 10 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 534810 = (5 1000) + (3 100) + (4 10) + (8 1) = (5 103) + (3 102) + (4 101) + (8 100) Counting in decimal numbers 1 11 21 31 41 51 61 71 81 91 2 12 22 32 42 52 62 72 82 92 3 13 23 33 43 53 63 73 83 93 4 14 24 34 44 54 64 74 84 94 5 15 25 35 45 55 65 75 85 95 6 16 26 36 46 56 66 76 86 96 7 17 27 37 47 57 67 77 87 97 8 18 28 38 48 58 68 78 88 98 9 19 29 39 49 59 69 79 89 99 10 20 30 40 50 60 70 80 90 100

Binary Numbers
What if we had only 2 symbols? A symbol/digit in binary number system is referred to as a bit. bit = an acronym of binary digit. 2 symbols: 0, 1 Examples: 1002 , 1101.1012 (base 2). 1101.1012 Blue represents Most Significant Bit (MSB); Pink represents Least Significant Bit (LSB). The point in the binary number is denoted as the binary point [separates the integer part (left) and the fraction part (right) of the number]. Digital circuits use binary number system to represent quantities.

Cont
Counting in binary numbers and their corresponding values in decimal numbers:

Octal Numbers
What if we had only 8 symbols?
8 symbols: 0, 1, 2, 3, 4, 5, 6, 7 Examples: 108 , 248 , 732.168 Radix (base), r = 8. Use to represent long binary numbers in computers and microprocessors.

Cont
Counting in octal numbers and their corresponding values in decimal numbers:

Hexadecimal Numbers
What if we had 16 symbols? 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Examples: A16 , 2B16 , 8AC3F.1D416 Radix (base), r = 16. Use to represent long binary numbers in computers and microprocessors. These digits can use to program machine language.

Cont
Counting in hexadecimal numbers and their corresponding values in decimal numbers:

Base Conversions
From binary to decimal
10011012 = (1 26) + (0 25) + (0 24) + (1 23) + (1 22) + (0 21) + (1 20) = (1 64) + (0 32) + (0 16) + (1 8) + (1 4) + (0 2) + (1 1) = 64 + 8 + 4 + 1 = 7710 11011002 = (1 26) + (1 25) + (0 24) + (1 23) + (1 22) + (0 21) + (0 20) = (1 64) + (1 32) + (0 16) + (1 8) + (1 4) + (0 2) + (0 1) = 64 + 32 + 8 + 4 = 10810 101002 = (1 24) + (0 23) + (1 22) + (0 21) + (0 20) = (1 16) + (0 8) + (1 4) + (0 2) + (0 1) = 16 + 4 = 2010

Cont
From octal to decimal
2618 = (2 82) + (6 81) + (1 80) = (2 64) + (6 8) + (1 1) = 128 + 48 + 1 = 17710 328 = (3 81) + (2 80) = (3 8) + (2 1) = 24 + 2 = 2610 3338 = (3 82) + (3 81) + (3 80) = (3 64) + (3 8) + (3 1) = 192 + 24 + 3 = 21910

Cont
From hexadecimal to decimal
7916 = (7 161) + (9 160) = (7 16) + (9 1) = 112 + 9 = 12110 E016 = (14 161) + (0 160) = (14 16) + (0 1) = 224 = 22410 AB16 = (10 161) + (11 160) = (10 16) + (11 1) = 160 + 11 = 17110

Cont
From decimal to binary

Cont
From decimal to binary
Some samples:
10810 54 0 27 0 13 1 6 1 3 0 1 1 0 1 11011002 24410 122 0 61 0 30 1 15 0 7 1 3 1 1 1 0 1 111101002 12810 64 0 32 0 16 0 8 0 4 0 2 0 1 0 0 1 100000002 5710 28 1 14 0 7 0 3 1 1 1 0 1 1110012

Cont
From decimal to octal

Cont
From decimal to octal Some examples:
10810 13 4 1 5 0 1 1548 24410 30 3 0 4 6 3 3648 12810 16 2 0 0 0 2 2008 5710 7 0 1 7 718

Cont
From decimal to hexadecimal

Cont
From decimal to hexadecimal
Examples:
10810 6 12 0 6 6C16 24410 15 4 0 15 F416 12810 8 0 5710 3 0

0 8 8016

9 3 3916

Cont
From binary to octal: - Start with right-most group of 3 bits, moving from right to left. - Covert each 3-bit group to the equivalent octal digit. - Add either one or two zeros to make a complete group for the left-most group if there are not enough three bits. 1101012 1001100110102 110100001002 6 5 = 658 4 6 3 2 = 46328 0110100001002 3 2 0 4 = 32048 From octal to binary: - Replace each octal digit with the appropriate 3 bits. 1 38 1 4 08 7 5 2 68 0010112 0011000002 1111010101102

Cont
From binary to hexadecimal: - Start with right-most group of 4 bits, moving from right to left. - Covert each 4-bit group to the equivalent hexadecimal symbol. - Add either one, two or three zeros to make a complete group for the left-most group if there are not enough four bits. 11001010010101112 1111110001011010012 C A 5 7 = CA5716 001111110001011010012 3 F 1 6 9 = 3F16916 From hexadecimal to binary: - Replace each hexadecimal symbol with the appropriate 4 bits. 9 7 4 216 C F 8 E16 11001111100011102 10010111010000102

Fractional Numbers
Decimal numbers: 12.3410 = 1 101 + 2 100 + 3 10-1 + 4 10-2 Binary to decimal: 0.10012 = 0 20 + 1 2-1 + 0 2-2 + 0 2-3 + 1 2-4 = 0 + 0.5 + 0 0.25 + 0 0.125 + 1 0.0625 = 0.562510 Octal to decimal: 761.548 = 7 82 + 6 81 + 1 80 + 5 8-1 + 4 8-2 = 7 64 + 6 8 + 1 1 + 5 0.125 + 4 0.015625 = 448 + 48 + 1 + 0.625 + 0.0625 = 497.687510 Hexadecimal to decimal: A.A116 = 10 160 + 10 16-1 + 1 16-2 =10.6289062510

Cont
From fractional decimal number to fractional binary number:
Start by multiplying the fractional part by 2 and then multiplying each resulting fractional part of the product by 2.

The whole procedures are also applicable for converting fractional decimal numbers to fractional octal numbers (fractional part 8) or to fractional hexadecimal numbers (fractional part 16).

Cont
Examples:
0.14110
0.282 0 1.128 1 2.256 2 0.564 0 1.024 1 4.096 4 1.128 1 0.192 0 1.536 1 0.256 0 1.536 1 8.576 8 0.512 0 4.288 4 9.216 9 1.024 1 2.304 2 3.456 3 0.048 0 2.432 2 7.296 7 0.096 0 3.456 3 4.736 4 0.192 0 3.648 3 11.776 B 0.384 0 5.184 5 12.416 C 0.768 0 1.472 1 0.24189374BC16 1.536 1 0.11014223351...8 0.001001000001...2

0.14110

0.14110

Arithmetic
Binary addition: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 Sum of 0 with carry of 0. Sum of 1 with carry of 0. Sum of 1 with carry of 0.

1 + 1 = 10 Sum of 0 with carry of 1.

Cont
Examples: (a) 1 1 + 1 1 1 1 0 1 1 1 + 1 1 1 0 1 0 3 + 3 6 7 + 3 1 0 (b) 1 0 0 + 1 0 1 1 0 1 1 0 + 1 0 0 1 0 1 0 4 + 2 6 6 + 4 1 0

(c)

(d)

Cont
Binary subtraction: 0 - 0 = 0 1 - 1 = 0 1 - 0 = 1 10 - 1 = 1 0 1 with borrow of 1.

Cont
Examples: 1 1 (a) - 0 1 1 0 3 - 1 2 (b) 1 1 - 1 0 0 1 3 - 2 1

Left column: When a 1 is borrowed, a 0 is left, so 0 0 = 0.

Middle column: Borrow 1 from next column to the left, then 10 1 = 1.

(c)

1 0 1 - 0 1 1 0 1 0

5 - 3 2
Right column: 1 1 = 0

Cont
Binary multiplication: 0 0 = 0 0 1 = 0 1 0 = 0 1 1 = 1

Cont
Examples: 1 1 (a) 1 1 1 1 Partial products + 1 1 1 0 0 1 3 x 3 9 (b)
Partial products

0 + 1 1 1 0 0

1 1 1 0 1 0

1 1 0 1 1 1 0 1 1

7 5 3 5

Cont
Binary division:
Follow the same procedure as division in decimal.

(b) (a) 1 0 1 1 1 1 0 1 1 0 0 0 2 3 6 6 0

1 1 0 1 1 1 0 1 1 0

1 0 0 0 0

3 2 6 6 0

Complements of Binary Numbers


Permit the representation of negative numbers. Types: 1s complement. 1 0 1 1 0 0 1 0 2s complement. 0 1 0 0 1 1 0 1 Ones complement inverse all the bits. + 1 0 1 0 0 1 1 1 0
Binary no. 1s comple. Add 1 2s comple.

Twos complement Add 1 to the LSB of the 1s complement. 2s complement = (1s complement) + 1

Signed Number Representations


Digital systems, such as computer, must be able to handle both positive and negative numbers. Signed binary number consists of both: (a) Sign positive (+) or negative (-) number. (b) Magnitude the value of the number. Sign bit of a signed binary number: (a) left-most bit in the number. (b) 0 positive number; 1 negative number. Three forms to represent signed integer numbers in binary numbers: (a) Sign-magnitude (least used). (b) 1s complement. (c) 2s complement (most important).

Sign-magnitude form representation Left-most bit sign bit. Remaining bits magnitude bits. Example: +25 is expressed as an 8-bit signed binary number. + 25 0 0 0 1 1 0 0 1
Only different in sign bit: 0 (+ve), 1 (-ve). Sign bit Magnitude bits

Cont

25 1 0 0 1 1 0 0 1
Sign bit Magnitude bits

Same magnitude bits

Cont
1s complement form representation Positive numbers are represented the same way as the positive sign-magnitude numbers. Negative numbers are the 1s complement of the corresponding positive numbers. Example: +25 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 -25

1s complement of the positive no.

Cont
2s complement form representation Positive numbers are represented the same way as the positive sign-magnitude numbers and 1s complement form. Negative numbers are the 2s complement of the corresponding positive numbers. Example: +25 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 1 1 -25

1s complement of the positive no. 2s complement of the positive no.

Cont
Exercise Express the decimal number -39 as an 8-bit number is the: (a) sign-magnitude form. (b) 1s complement form. (c) 2s complement form.

Ans.: (a) 10100111, (b) 11011000, (c) 11011001

Cont
Arithmetic operations with signed numbers The arithmetic operations are performed on 8-bit signed number represented in the 2s complement form. Addition: Case 1: Both numbers are positive. 0 0 0 0 0 1 1 1 + 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1
Augend Addend sum

7 + 4 1 1

Take sum is positive and is therefore in true (uncomplemented) binary.

Cont
Arithmetic operations with signed numbers Addition: Case 2: Positive number with magnitude larger than negative number. 0 0 0 0 1 1 1 1 + 1 1 1 1 1 0 1 0 1 0 0 0 0 1 0 0 1
Discard carry
Augend Addend sum

1 5 + -6 9

Take the 2s complement form of +6 (00000110) gives -6.

Take sum is positive and is therefore in true (uncomplemented) binary.

Cont
Arithmetic operations with signed numbers Addition: Case 3: Negative number with magnitude larger than positive number. 0 0 0 1 0 0 0 0 + 1 1 1 0 1 0 0 0 1 1 1 1 1 0 0 0
Augend Addend sum

1 6 + -2 4 - 8

Take the 2s complement form of +24 (00011000) gives -24.


Take sum is negative and therefore in 2s complement form.

Cont
Arithmetic operations with signed numbers Addition: Case 4: Both numbers are negative. 1 1 1 1 1 0 1 1 + 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 0
Discard carry
Augend Addend sum

- 5 + - 9 - 1 4

Take the 2s complement form of +5 (00000101) and +9 (00001001) give -5 and -9, respectively.

Take sum is negative and therefore in 2s complement form.

Cont
Overflow condition: When two numbers are added and the number of bits required to represent the sum exceeds the number of bits in the two numbers. Overflow result is indicated by the incorrect sign bit. Occur when both numbers are positive or negative. 0 1 1 1 1 1 0 1 + 0 0 1 1 1 0 1 0 1 0 1 1 0 1 1 1
Sign incorrect Magnitude incorrect

1 2 5 + 5 8 1 8 3
183 requires 8 magnitude bits. Thus, a carry is into the sign bit which yields overflow.

Cont
Subtraction of signed numbers The subtraction operation changes the sign of the subtrahend and adds it to the minuend. The sign of a positive and negative binary number is changed by taking its 2s complement. Subtraction process: Take the 2s complement of the subtrahend, add to the minuend, and discard any final carry bit.

Cont
Examples: 8 3 = 8 + (-3) = 5. 0 0 0 0 1 0 0 0 + 1 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 1
Discard carry
Minuend (+8) 2s complement of subtrahend +3, (-3) Difference (+5)

Examples: 12 (-9) = 12 + 9 = 21. 0 0 0 0 1 1 0 0 + 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1


Minuend (+12) 2s complement of subtrahend -9, (+9) Difference (+21)

Cont
Examples: -25 (+19) = -25 + (-19) = -44. 1 1 1 0 0 1 1 1 + 1 1 1 0 1 1 0 1 1 1 1 0 1 0 1 0 0
Discard carry
Minuend (-25) 2s complement of subtrahend +19, (-19) Difference (-44)

Examples: -120 (-30) = -120 + 30 = -90. 1 0 0 0 1 0 0 0 + 0 0 0 1 1 1 1 0 1 0 1 0 0 1 1 0


Minuend (-120) 2s complement of subtrahend -30, (+30) Difference (-90)

Cont
Multiplication of signed numbers Partial product method: the multiplicand is multiplied by each multiplier digit beginning with LSD. Partial product - the result of the multiplication of the multiplicand by a multiplier digit. Each successive partial product is shifted one place to the left. When all the partial products have been produced, add them together to get the final product. If the signs of the numbers are the same, the product is positive. If the signs of the numbers are different, the product is negative. Both numbers must be in true (uncomplemented) form.

Cont
Example: Multiply the signed binary numbers 01010011 (multiplicand) and 11000101 (multiplier). Step 1: Sign bit of multiplicand is 0, sign bit of multiplier is 1. Thus, the sign bit of the product will be 1 (negative). Step 2: Take 2s complement of the multiplier to put it in true form. 11000101 00111011 Step 3: Use only the magnitude bits in the multiplication process.

1 0 1 0 0 1 1 x 0 1 1 1 0 1 1 1 0 1 0 0 1 1 + 1 0 1 0 0 1 1 1 1 1 1 1 0 0 1 + 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 1 + 1 0 1 0 0 1 1 1 1 1 0 0 1 0 0 0 1 + 1 0 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 0 1 + 1 0 1 0 0 1 1 1 0 0 1 1 0 0 1 0 0 0 0 1 + 0 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1

Cont Multiplicand
Multiplier 1st partial product 2nd partial product Sum of 1st and 2nd 3rd partial product Sum 4th partial product Sum 5th partial product Sum 6th partial product Sum 7th partial product Final product

Cont
Step 4: Since the sign of the product is a 1 as determined in step 1, take the 2s complement of the product. 1001100100001 0110011011111 Attach the sign bit. 10110011011111

Cont
Division of signed numbers The division operation in computers is accomplished using subtraction. Quotient - the result of a division. If the signs of the numbers are the same, the quotient is positive. If the signs of the numbers are different, the quotient is negative. Both numbers must be in true (uncomplemented) form.

Cont
Example: Divide 01100100 (dividend) by 00011001(divisor). Step 1: The signs of both numbers are positive, thus the quotient will be positive and set it initially to zero, 00000000. Step 2: Subtract the divisor from the dividend using 2s complement addition and discard the carry.

0 1 1 0 0 1 0 0 + 1 1 1 0 0 1 1 1 1 0 1 0 0 1 0 1 1
Discard carry

Dividend 2s complement of the divisor Positive 1st partial remainder

Add 1 to quotient: 00000001

Cont
Step 3: Since the 1st partial remainder is positive, repeat step 2 until the partial remainder is zero or negative (the division is complete). - So, subtract the divisor from the 1st partial remainder using 2s completion addition.

0 1 0 0 1 0 1 1 + 1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 0

1st partial remainder 2s complement of the divisor Positive 2nd partial remainder

Add 1 to quotient: 00000010

Subtract the divisor from the 2nd partial remainder using 2s completion addition.

Cont

0 0 1 1 0 0 1 0 + 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1

2nd partial remainder

2s complement of the divisor Positive 3rd partial remainder

Add 1 to quotient: 00000011 Subtract the divisor from the 3rd partial remainder using 2s completion addition.

Add 1 to quotient: 00000100 Since the remainder is zero, division is complete, and the final quotient is 00000100.

0 0 0 1 1 0 0 1 + 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0

3rd partial remainder 2s complement of the divisor Zero remainder

Binary Coded Decimal (BCD)


BCD is a way to express each of the decimal digits with a binary code. The 8421 code is a type of BCD code and is categorised as weighted code. 8421 indicates the binary weights of four bits (23,22,21,20). The other six combinations that are not used (1010, 1011, 1100, 1101, 1110, 1111) are named as invalid codes in 8421 BCD code. BCD code used in binary interfaces such as keypad inputs and digital readouts.
Decimal digit 0 1 2 3 4 5 6 7 8 9 BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

Cont
Decimal number to BCD:

0 0 1 1 0 1 0 1
BCD to Decimal number:

0 0 0 1 0 1 1 1 0 0 0 0

1 0 0 0 0 1 1 0 8 6

0 0 1 1 0 1 0 1 0 0 0 1 3 5 1

Cont
BCD addition (sum 9): 1. Add the 2 BCD numbers using the rules for binary addition.

(a)

0 0 1 1 + 0 1 0 0 0 1 1 1 0 0 1 0 + 0 0 0 1 0 0 1 1

3 + 4 7 0 0 1 1 0 1 0 1 1 0 0 0 2 3 + 1 5 3 8

(b)

Cont
BCD addition (sum > 9): If a 4-bit sum > 9, add 6 (0110) to the 4-bit sum. If a carry results when 6 is added, simply add the carry to the next 4-bit group.

Carry 1 to next 4-biy group

1 + 0 Invalid BCD no. (>9) 1 Add 6 + 0 0 0 0 1 0 1 (a)

0 1 1 1 0 3

0 0 0 1 1

1 0 1 0 1

9 + 4 1 3

Cont
(b)
Add 6 to both groups

0 0 0 1 1

0 + 0 1 + 0 0

1 1 0 1 0 2

1 0 1 1 1

0 1 1 0 0

0 + 0 1 + 0 0

1 0 0 1 0 0

1 1 1 1 0

1 1 0 0 0

6 7 + 5 3 1 2 0

Carry 1 to next 4-biy group

Both groups are invalid BCD no. (>9)

Computer codes
Gray code: Unweighted (no specific weights assigned to the bit positions) and is not an arithmetic code. An example of the unitdistance code only a single bit change from one code word to the next in sequence. Examples of applications of Gray code:
Use in the conversion of an analog quantity into a digital representation. Use in shaft position encoders.

Decimal digit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

Gray code 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000

Cont
Binary-to-Gray Code Conversion: The MSB in Gray code is the same as the corresponding MSB in the binary number. From left to right, add each adjacent pair of the binary code bits to get the next Gray code bit. Discard carries. Example: convert binary number 10110 to Gray code.
1 - + 0 - + 1 - + 1 - + 0 1 1 1 0 1 Gray Binary

The Gray code is 11101.

Cont
Gray-to-Binary Code Conversion: The MSB in Binary code is the same as the corresponding MSB in the Gray code. Add each binary code bit generated to the Gray code bit in the next adjacent position. Discard carries. Example: convert Gray code word 11011 to binary code.
1 1 + 1 0 + 0 0 + 1 1 + 1 0 Binary Gray

The binary number is 10010.

Cont
ASCII code: Abbreviation for American Standard Code for Information Interchange. Unweighted code. An example of Alphanumeric code a set of codes that represent numbers, alphabet characters, symbols and various instructions necessary for conveying information. Has 128 characters and symbols represented by 7-bit binary code. Can be considered as 8-bit code with MSB always 0.

Cont
The first thirty-two ASCII characters - nongraphic commands, never printed or displayed, used for control purposes. Other characters can be printed or displayed.

e.g.: Digital 44 69 67 69 74 61 6C

Error Detection
The transmission of binary data and codes from one location to another is the most frequent operation performed in digital systems. For example:
the transmission of digitized voice over a microwave link. The storage of data in and retrieval of data from external memory devices such as magnetic tape and disk.

Cont
Whenever information is transmitted from one device (transmitter) to another device (receiver), there is a possibility that errors can occur such that the receiver does not receive the identical information that was sent by the transmitter.

Transmitter

Receiver

Cont
The transmitter sends a relatively noise-free serial digital signal over a signal line to a receiver. However, by the time the signal reaches the receiver , it contains a certain degree of noise superimposed on the original signal. Occasionally, the noise is large enough in amplitude that it will alter the logic level of the signal as it does at point X.

Cont
A parity bit is an extra bit that is attached to a code group that is being transferred from location to another. The parity bit is made either 1 or 0, depending on the number of 1s that are contained in the code group. Two different methods are used: Even parity and Odd parity.

Cont
In the even-parity method, the value of the parity bit is chosen so that the total number of 1s in the code group (including the parity bit) is an even number. For example, suppose that the group is 1000011. This is the ASCII character C. The code has three 1s. Therefore, we will add a parity bit of 1 to make the total number of 1s an even number.

Cont
The new code group, including the parity bit, thus becomes 11000011
parity bit

If the group contains an even number of 1s to begin with, the parity bit is given a value of 0. For example, if the code group were 1000001 (ASCII code for A), the assigned parity bit would be 0, so that the new code, including the parity bit, would be 01000001.

Cont
The odd-parity method is exactly the same way except that the parity bit is chosen so the total number of 1s (including the parity bit) is an odd number. The parity bit is issued to detect any singlebit errors. For example, suppose that the character A is being transmitted and oddparity is being used. The transmitted code would be 11000001.

Cont
When the receiver circuit receives this code, it will check that the code contains an odd number of 1s (including parity bit). If so, the receiver will assume that the code has been correctly received. Now, suppose that because of some noise or malfunction, the receiver actually receives the following code: 11000000.

Cont
The receiver will find that this code has an even number of 1s. This tells the receiver that there must be an error in the code. However, there is no way that the receiver can tell which bit is in error. It should be apparent that this parity method would not work if two bits were in error, because two errors would not change the oddness or evenness of the number of 1s in the code.

THE END

Vous aimerez peut-être aussi