binary decimal and hexadecimal

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

Upload: thiva

Post on 23-Oct-2015

102 views

Category:

Documents


6 download

DESCRIPTION

Binary Decimal and HexadecimalNumber Systems and Codes

TRANSCRIPT

Page 1: Binary Decimal and Hexadecimal

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

Page 2: Binary Decimal and Hexadecimal

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).

Page 3: Binary Decimal and Hexadecimal

Cont’• Some examples of positional number systems:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,FHexadecimal160,1,2,3,4,5,6,7,8,9,A,BDuodecimal120,1,2,3,4,5,6,7,8,9Decimal100,1,2,3,4,5,6,7Octal80,1,2,3,4Quinary50,1,2,3Quaternary40,1,2Ternary30,1Binary2Digit symbolsNumber SystemBase

Page 4: Binary Decimal and Hexadecimal

The weighting structures of number systems• Decimal number

10n-1……103 102 101100.10-1 10-2 10-3……10-n

Decimal point• Binary number

2n-1……23 22 2120.2-1 2-2 2-3……2-n

Binary point• Octal number

8n-1……83 82 8180.8-1 8-2 8-3……8-n

Octal point• Hexadecimal number

16n-1……163 162 161160.16-1 16-2 16-3……16-n

Hexadecimal point

Cont’

Page 5: Binary Decimal and Hexadecimal

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.

Page 6: Binary Decimal and Hexadecimal

Cont’• Text:

– one

– two

– three

– four

– five

– six

– seven

– eight

– nine

– ten

Page 7: Binary Decimal and Hexadecimal

Cont’• Marks:

– |

– ||

– |||

– ||||

– ||||

– |||| |

– |||| ||

– |||| |||

– |||| ||||

– |||| ||||

Page 8: Binary Decimal and Hexadecimal

Cont’• Roman numbers:

– I

– II

– III

– IIII

– V

– VI

– VII

– VIII

– VIIII

– X

Page 9: Binary Decimal and Hexadecimal

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 912 12 22 32 42 52 62 72 82 923 13 23 33 43 53 63 73 83 934 14 24 34 44 54 64 74 84 945 15 25 35 45 55 65 75 85 956 16 26 36 46 56 66 76 86 967 17 27 37 47 57 67 77 87 978 18 28 38 48 58 68 78 88 989 19 29 39 49 59 69 79 89 99

10 20 30 40 50 60 70 80 90 100

Page 10: Binary Decimal and Hexadecimal

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.

Page 11: Binary Decimal and Hexadecimal

Cont’• Counting in binary numbers and their corresponding

values in decimal numbers:

Page 12: Binary Decimal and Hexadecimal

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.

Page 13: Binary Decimal and Hexadecimal

Cont’• Counting in octal numbers and their corresponding

values in decimal numbers:

Page 14: Binary Decimal and Hexadecimal

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.

Page 15: Binary Decimal and Hexadecimal

Cont’• Counting in hexadecimal numbers and their

corresponding values in decimal numbers:

Page 16: Binary Decimal and Hexadecimal

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

Page 17: Binary Decimal and Hexadecimal

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

Page 18: Binary Decimal and Hexadecimal

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

Page 19: Binary Decimal and Hexadecimal

Cont’• From decimal to binary

Page 20: Binary Decimal and Hexadecimal

Cont’• From decimal to binary

Some samples:

10810 24410 12810 571054 0 122 0 64 0 28 127 0 61 0 32 0 14 013 1 30 1 16 0 7 06 1 15 0 8 0 3 13 0 7 1 4 0 1 11 1 3 1 2 0 0 10 1 1 1 1 0 → 1110012

→ 11011002 0 1 0 1→ 111101002 → 100000002

Page 21: Binary Decimal and Hexadecimal

Cont’• From decimal to octal

Page 22: Binary Decimal and Hexadecimal

Cont’

• From decimal to octalSome examples:

10810 24410 12810 571013 4 30 4 16 0 7 11 5 3 6 2 0 0 70 1 0 3 0 2

→ 1548 → 3648 → 2008 → 718

Page 23: Binary Decimal and Hexadecimal

Cont’• From decimal to hexadecimal

Page 24: Binary Decimal and Hexadecimal

Cont’

• From decimal to hexadecimalExamples:

10810 24410 12810 57106 12 15 4 8 0 3 90 6 0 15 0 8 0 3

→ 6C16 → F416 → 8016 → 3916

Page 25: Binary Decimal and Hexadecimal

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 01101000010023 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 680010112 0011000002 1111010101102

Page 26: Binary Decimal and Hexadecimal

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 0011111100010110100123 F 1 6 9 = 3F16916

• From hexadecimal to binary:- Replace each hexadecimal symbol with the appropriate 4 bits.

C F 8 E16 9 7 4 21611001111100011102 10010111010000102

Page 27: Binary Decimal and Hexadecimal

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

Page 28: Binary Decimal and Hexadecimal

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).

Page 29: Binary Decimal and Hexadecimal

Cont’• Examples:

0.14110 0.14110 0.141100.282 0 1.128 1 2.256 20.564 0 1.024 1 4.096 41.128 1 0.192 0 1.536 10.256 0 1.536 1 8.576 80.512 0 4.288 4 9.216 91.024 1 2.304 2 3.456 30.048 0 2.432 2 7.296 70.096 0 3.456 3 4.736 40.192 0 3.648 3 11.776 B0.384 0 5.184 5 12.416 C0.768 0 1.472 1 → 0.24189374BC…161.536 1 → 0.11014223351...8→ 0.001001000001...2

Page 30: Binary Decimal and Hexadecimal

Arithmetic• Binary addition:

Sum of 0 with carry of 0.0=0+0

Sum of 0 with carry of 1.10=1+1

Sum of 1 with carry of 0.1=0+1

Sum of 1 with carry of 0.1=1+0

Page 31: Binary Decimal and Hexadecimal

Cont’• Examples:

(a)

60113+11+311 (b)

+60112+014001

(c)

1+

010103+117111 (d)

1+

010104+0016011

Page 32: Binary Decimal and Hexadecimal

Cont’• Binary subtraction:

0=0-0

0 – 1 with borrow of 1.1=1-10

1=0-1

0=1-1

Page 33: Binary Decimal and Hexadecimal

Cont’• Examples:

(a)

2011-10-311 (b)

1102-01-311

110(c)

2003-10-511

Right column: 1 – 1 = 0

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

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

Page 34: Binary Decimal and Hexadecimal

Cont’• Binary multiplication:

0=0×0

1=1×1

0=0×1

0=1×0

Page 35: Binary Decimal and Hexadecimal

Cont’• Examples:

1+

10011

(a)

9113x11×311

1+

01

110011

000

×(b)

531115×1017111

Partial products

Partial products

Page 36: Binary Decimal and Hexadecimal

Cont’• Binary division:

Follow the same procedure as division in decimal.

1 1

0000

(a)

61163011201

0001

1 0

001

(b)

60162011311

Page 37: Binary Decimal and Hexadecimal

Complements of Binary Numbers• Permit the representation of negative numbers.• Types:

– 1’s complement.– 2’s complement.

• One’s complement– inverse all the bits.

• Two’s complement– Add 1 to the LSB of the 1’s complement.– 2’s complement = (1’s complement) + 1

2’s comple.

Add 1

1’s comple.

Binary no.

+10110010

1

0

0

1

0110101

010101

Page 38: Binary Decimal and Hexadecimal

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) 1’s complement.(c) 2’s complement (most important).

Page 39: Binary Decimal and Hexadecimal

Cont’Sign-magnitude form representation• Left-most bit – sign bit. • Remaining bits – magnitude bits. • Example: +25 is expressed as an 8-bit signed

binary number.

1001Magnitude bitsSign bit

100025+

1001Magnitude bitsSign bit

100125-

Same magnitude bits

Only different in sign bit: 0 (+ve), 1 (-ve).

Page 40: Binary Decimal and Hexadecimal

Cont’1’s complement form representation• Positive numbers are represented the same way as

the positive sign-magnitude numbers.• Negative numbers are the 1’s complement of the

corresponding positive numbers.• Example:

-2501100111

0+25

10011001’s complement of the positive no.

Page 41: Binary Decimal and Hexadecimal

Cont’2’s complement form representation• Positive numbers are represented the same way as

the positive sign-magnitude numbers and 1’s complement form.

• Negative numbers are the 2’s complement of the corresponding positive numbers.

• Example:

-251110011101100111

0+25

10011001’s complement of the positive no.

2’s complement of the positive no.

Page 42: Binary Decimal and Hexadecimal

Cont’Exercise• Express the decimal number -39 as an 8-bit

number is the:(a) sign-magnitude form.(b) 1’s complement form.(c) 2’s complement form.

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

Page 43: Binary Decimal and Hexadecimal

Cont’Arithmetic operations with signed numbersThe arithmetic operations are performed on 8-bit signed number represented in the 2’s complement form.• Addition:

Case 1: Both numbers are positive.

sum

Addend

147

1+

Augend

+1101000000100000

0 1110000

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

Page 44: Binary Decimal and Hexadecimal

Cont’Arithmetic operations with signed numbers• Addition:

Case 2: Positive number with magnitude larger than negative number.

1

sum

Addend

9-65

+

Augend

1+

1001000001011111

0 1111000

Discard carryTake the 2’s complement form of +6 (00000110) gives -6.

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

Page 45: Binary Decimal and Hexadecimal

Cont’Arithmetic operations with signed numbers• Addition:

Case 3: Negative number with magnitude larger than positive number.

+-

-21

sum

Addend

846Augend

+0001111100010111

0 0000100

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

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

Page 46: Binary Decimal and Hexadecimal

Cont’Arithmetic operations with signed numbers• Addition:

Case 4: Both numbers are negative.

495

1--

-+

sum

Addend

Augend

1+

0100111111101111

1 1101111

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

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

Discard carry

Page 47: Binary Decimal and Hexadecimal

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.

1

1

385

852

++1110110101011100

0 1011111

Sign incorrect Magnitude incorrect183 requires 8 magnitude bits. Thus, a carry is into the sign bit which yields overflow.

Page 48: Binary Decimal and Hexadecimal

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 it’s 2’s complement.• Subtraction process:

Take the 2’s complement of the subtrahend, add to the minuend, and discard any final carry bit.

Page 49: Binary Decimal and Hexadecimal

Cont’Examples: 8 – 3 = 8 + (-3) = 5.

Difference (+5)

2’s complement of subtrahend +3, (-3)

Minuend (+8)

1

+

10100000

101111110 0001000

Discard carry

Examples: 12 – (-9) = 12 + 9 = 21.

Difference (+21)

2’s complement of subtrahend -9, (+9)

Minuend (+12)

+

10101000

100100000 0011000

Page 50: Binary Decimal and Hexadecimal

Cont’Examples: -25 – (+19) = -25 + (-19) = -44.

Difference (-44)

2’s complement of subtrahend +19, (-19)

Minuend (-25)

1

+

00101011

101101111 1110011

Discard carry

Examples: -120 – (-30) = -120 + 30 = -90.

Difference (-90)

2’s complement of subtrahend -30, (+30)

Minuend (-120)

+

01100101

011110001 0001000

Page 51: Binary Decimal and Hexadecimal

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.

Page 52: Binary Decimal and Hexadecimal

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 2’s complement of the multiplier to put it in true form.

11000101 → 00111011

Step 3: Use only the magnitude bits in the multiplication process.

Page 53: Binary Decimal and Hexadecimal

Cont’

Final product10000100110017th partial product0000000+

Sum10000100110016th partial product1100101+

Sum1000001100015th partial product1100101+

Sum10001001114th partial product1100101+

+00

+

Sum100111113rd partial product000000Sum of 1st and 2nd100111112nd partial product11001011st partial product

MultiplierMultiplicand

x110010111011101100101

Page 54: Binary Decimal and Hexadecimal

Cont’Step 4: Since the sign of the product is a 1 as determined in step 1, take the 2’s complement of the product.

1001100100001 → 0110011011111

Attach the sign bit.10110011011111

Page 55: Binary Decimal and Hexadecimal

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.

Page 56: Binary Decimal and Hexadecimal

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 2’s complement addition and discard the carry.

Positive 1st partial remainder

2’s complement of the divisor

Dividend

1+

1101001011100111

0 0010011

Discard carry Add 1 to quotient: 00000001

Page 57: Binary Decimal and Hexadecimal

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 2’s completion addition.

Positive 2nd partial remainder

2’s complement of the divisor

1st partial remainder

+0100110011100111

0 1101001

Add 1 to quotient: 00000010

Page 58: Binary Decimal and Hexadecimal

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

Positive 3rd partial remainder

2’s complement of the divisor

2nd partial remainder

+1001100011100111

0 0100110

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

Zero remainder

2’s complement of the divisor

3rd partial remainder

+0000000011100111

0 1001100

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

Page 59: Binary Decimal and Hexadecimal

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.

10019100080111701106010150100400113001020001100000BCDDecimal digit

Page 60: Binary Decimal and Hexadecimal

Cont’Decimal number to BCD:

10101100↓↓

53

111 0↓

0

00001000↓↓

71

↓↓68

01100001

BCD to Decimal number:

1↓

0 0 0 1↓↓53

10101100

Page 61: Binary Decimal and Hexadecimal

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

addition.(a)

711104+0010+31100

(b)+ +

83000111005110101000

100 1 320100

Page 62: Binary Decimal and Hexadecimal

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.

(a)

310 0 0 1 1100

0110+3110114+0010+91001

Invalid BCD no. (>9)

Add 6

Carry 1 to next 4-biy group

Page 63: Binary Decimal and Hexadecimal

Cont’

1+

+256

001

0

(b)

0200100

01011

11101

00110

00000110+

0101013+1100+71110

Both groups are invalid BCD no. (>9)

Add 6 to both groups

Carry 1 to next 4-biy group

Page 64: Binary Decimal and Hexadecimal

Computer codesGray code:• Unweighted (no specific

weights assigned to the bit positions) and is not an arithmetic code.

• An example of the unit-distance 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.

1000111115

1001111014

1011110113

1010110012

1110101111

1111101010

1101110001000101011101100010001100010000

Gray code

10019100080111701106010150100400113001020001100000BCDDecimal digit

Page 65: Binary Decimal and Hexadecimal

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.

Gray10111

↓↓↓↓↓

Binary0→+-1→+-1→+-0→+-1

The Gray code is 11101.

Page 66: Binary Decimal and Hexadecimal

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.

Binary0⁄1⁄0⁄0⁄1

↓+↓+↓+↓+↓

Gray1→1→0→1→1

The binary number is 10010.

Page 67: Binary Decimal and Hexadecimal

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.

Page 68: Binary Decimal and Hexadecimal

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”

Page 69: Binary Decimal and Hexadecimal

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.

Page 70: Binary Decimal and Hexadecimal

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 ReceiverX

Page 71: Binary Decimal and Hexadecimal

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’.

Page 72: Binary Decimal and Hexadecimal

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.

Page 73: Binary Decimal and Hexadecimal

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.

Page 74: Binary Decimal and Hexadecimal

Cont’• The new code group, including the parity bit,

thus becomes

11000011parity 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.

Page 75: Binary Decimal and Hexadecimal

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 single-bit errors. For example, suppose that the character “A” is being transmitted and odd-parity is being used. The transmitted code would be 11000001.

Page 76: Binary Decimal and Hexadecimal

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.

Page 77: Binary Decimal and Hexadecimal

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.

Page 78: Binary Decimal and Hexadecimal

THE END