75
1 EENG 2710 Chapter 1 Number Systems and Codes

EENG 2710 Chapter 1

  • Upload
    shayna

  • View
    77

  • Download
    0

Embed Size (px)

DESCRIPTION

EENG 2710 Chapter 1. Number Systems and Codes. Chapter 1 Homework. 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a. Number Systems. Binary Number System. Uses two digits, 0 and 1. Represents any number using the positional notation. Positional Notation. - PowerPoint PPT Presentation

Citation preview

Page 1: EENG 2710 Chapter 1

1

EENG 2710 Chapter 1

Number Systems and Codes

Page 2: EENG 2710 Chapter 1

2

Chapter 1 Homework

1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a

Page 3: EENG 2710 Chapter 1

3

Number Systems

Page 4: EENG 2710 Chapter 1

4

Binary Number System

• Uses two digits, 0 and 1.• Represents any number using the positional

notation.

Page 5: EENG 2710 Chapter 1

5

Positional Notation

• The value of a digit depends on its placement within a number.

• In base 10, the positional values are (starting to the left of the decimal) –1 (100), 10 (101), 100 (102), 1000 (103), etc.

• In base 2, the positional values are1 (20), 2 (21), 4 (22), 8 (23), etc.

Page 6: EENG 2710 Chapter 1

6

Binary Weights

27 26 25 24 23 22 21 20

128 64 32 16 8 4 2 1

Page 7: EENG 2710 Chapter 1

7

Fractional Binary Weights

2-1 2-2 2-3 2-4

½ ¼ 1/8 1/160.5 0.25 0.125 0.0625

Page 8: EENG 2710 Chapter 1

8

Bit

• Shorthand for binary digit, a logic 0 or 1.• The most significant bit (MSB) is the

leftmost bit of a binary number.• The least significant bit (LSB) is the

rightmost bit of a binary number.

Page 9: EENG 2710 Chapter 1

9

Binary Inputs

• Digital circuits operate by accepting logic levels (0,1) at their input(s).

• The corresponding output(s) logic level will change (0,1).

Page 10: EENG 2710 Chapter 1

10

Binary Inputs

Page 11: EENG 2710 Chapter 1

11

4-Input Digital Circuit

Page 12: EENG 2710 Chapter 1

12

Base Conversions Methods

• Series substitution method• Sum powers of 2• Radix method

– Repeated Division– Repeated Multiplication

Page 13: EENG 2710 Chapter 1

13

Series Substitution Method(Binary to Decimal)

13 1048

1)(12)04)(18)(1 )2(1)2(0)2(1)2(1 1101 0123

(

Page 14: EENG 2710 Chapter 1

14

Sum Powers of 2(Decimal to Binary)

• Step 1:– Determine the largest power of 2 less than or

equal to the number to be converted.– Place a 1 in that positional location.

• Convert 5710 to binary• 6410 5710 3210

32 16 8 4 2 11

Page 15: EENG 2710 Chapter 1

15

Sum Powers of 2• Step 2:

– Subtract the number found in Step 1 from the number to be converted. • 57 – 32 = 25

– For the new number, determine if the next lowest power of 2 is less than or equal to that number.• 25 – 16 = 9

Page 16: EENG 2710 Chapter 1

16

Sum Powers of 2

• Step 3:– If the new power of two from Step 2 is larger,

place a 0 in that positional location. – If the new value is less than or equal, place a 1

in that positional location.

Page 17: EENG 2710 Chapter 1

17

Sum Powers of 2

• Step 4:– Repeat Steps 2 and 3 until there is nothing left

to subtract. – All remaining bits are set to 0.

5710 = 1110012

32 16 8 4 2 11 1 1 0 0 1

Page 18: EENG 2710 Chapter 1

18

Radix Method (Repeated Division by 2)

1 2 5 11 23 46 22 4 10 22 46

1 0 1 1 1 0

4610 = 1011102

Page 19: EENG 2710 Chapter 1

19

Fractional Binary Numbers

• Radix point:– The generalized decimal point. The dividing

line between positive and negative powers for positional multipliers.

• Binary point:– The radix point for binary numbers.

Page 20: EENG 2710 Chapter 1

20

Fractional Binary Values

• The value immediately to the right of the binary point is 2–1 = 0.5.

• The next value to the right is 2–2 = 0.25.• The next value to the right is 2–4 = 0.125,

and so on.

Page 21: EENG 2710 Chapter 1

21

Series Substitution Method(Binary Fraction to Decimal Fraction)

7031250 45/64

1/641/161/801/2 )2(1)2(0)2(1

)2(1)2(0)2(1 10110106-5-4-

-3-2-1

.

.

Page 22: EENG 2710 Chapter 1

22

Radix Method for 0.210 to Binary (Repeated Multiplication by 2)

• Step 1:Multiply the decimal fraction by 2.• Step 2:

Integer part is 0 or 1 left of decimal point. 0.2 x 2 = 0.4 Integer part = 0

0.4 x 2 = 0.8 Integer part = 0 0.8 x 2 = 1.6 Integer part = 1 0.6 x 2 = 1.2 Integer part = 1 0.2 x 2 = 0.4 Integer part = 0 (stop

0011repeats)Read integer parts from top to bottom Therefore, 0.210 = 0.0011 0011 0011

Page 23: EENG 2710 Chapter 1

23

Hexadecimal Numbers

• Base 16 number system.• Primarily used as a shorthand form of

binary numbers.

Page 24: EENG 2710 Chapter 1

24

Counting in Hexadecimal

• Values range from 0 to F with the letters A to F used to represent the values 10 to 15 respectively.

• Positional multipliers are powers of 16:160 = 1, 161 = 16, 162 = 256, etc.

Page 25: EENG 2710 Chapter 1

25

Hexadecimal vs. Decimal Numbers

Decimal

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

Hexadecimal

0 1 2 3 4 5 6 7 8 9 A B C D E F

Page 26: EENG 2710 Chapter 1

26

Counting In Hexadecimal

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F

20,21,22,23,24,25,26,27,28,29,2A,2B,2C,2D,2E,2F

30,31,32,33,34,35,36,37,38,39,3A,3B,3C,3D,3E,3F

Page 27: EENG 2710 Chapter 1

27

Decimal-to-Hexadecimal Conversion(Repeated division by 16)

7 123 1973 31581 16112 1968 31568

7 11 5 137 B 5 D

3158110 = 7B5DH

Page 28: EENG 2710 Chapter 1

28

Hex-Decimal-Binary Table

Hex Decimal Binary Hex (Cont)

Decimal Binary

0 0 0000 8 8 10001 1 0001 9 9 10012 2 0010 A 10 10103 3 0011 B 11 10114 4 0100 C 12 11005 5 0101 D 13 11016 6 0110 E 14 11107 7 0111 F 15 1111

Page 29: EENG 2710 Chapter 1

29

Conversion Between Hexadecimal and Binary

• Each hexadecimal digit represents 4 binary bits.

F D 6 9 1111 1101 0110 1001

FD69H = 11111101011010012

Page 30: EENG 2710 Chapter 1

30

Signed/Unsigned Binary Numbers• Signed Binary Number:

– A binary number of fixed length whose sign (+/–) is represented by one bit (usually MSB) and its magnitude by the remaining bits.

• Unsigned Binary Number:– A binary number of fixed length whose sign

is not specified by a bit. All bits are magnitude and the sign is assumed +.

Page 31: EENG 2710 Chapter 1

31

Unsigned Binary Arithmetic• Sum:

– Result of an Addition Operation of two (or more) binary numbers (operands).

• Carry:– A digit (or bit) that is carried over to the next most

significant bit during an n-Bit addition operation.• The carry bit is a 1 if the result was too large to be

expressed in n bits.

Page 32: EENG 2710 Chapter 1

32

Basic Rules (Unsigned)

bit outCarry 101000001 11100

00100111 101010101110 10010

1111 next tocarry 1

bit outCarry 101000001 11100

00100111 101010101110 10010

1111 next tocarry 1

Page 33: EENG 2710 Chapter 1

33

Basic Subtraction

• Basic Subtraction of x = a – b, with a = minuend, b = subtrahend, and x = difference or result.

• Requires a Borrow Bit if a < b.• There are other forms of subtraction such as

2’s Complement Addition used by microprocessors (such as in a PC).

Page 34: EENG 2710 Chapter 1

34

Binary Subtraction with Borrow Examples

1 0101 1 10 101 -

LSB to ripplesBorrow 0111(10) 100001 010 1 100 1001 -

StageBorrow 110(10) 1110

Page 35: EENG 2710 Chapter 1

35

Signed Binary Numbers

• Sign Bit:– A bit (usually the MSB) that indicates whether

a number is positive (= 0) or negative (= 1).• Magnitude Bits:

– The bits of a signed binary number that tell how large it is in value.

Page 36: EENG 2710 Chapter 1

36

Signed Binary Numbers

• True-Magnitude Form:– A form of signed binary whose magnitude bits are the

TRUE binary form (not complements).• 1’s Complement:

– A form of signed binary in which negative numbers are created by complementing all bits.

• 2’s Complement:– A form of signed binary in which the negative numbers

are created by complementing all the bits and adding a 1 (1’s Complement + 1).

Page 37: EENG 2710 Chapter 1

37

True-Magnitude Form• 5-Bit Numbers Negative Sign (S = 1)• +25 = 011001 (Note sign bit (MSB) Sign = 0)• –25 = 111001 (Same as +25 with sign = 1)• +12 = 001100• –12 = 101100

Page 38: EENG 2710 Chapter 1

38

1’s Complement Form

• 8-Bit 1’s Complement Negative (S = 1)• +57 = 00111001• –57 = 11000110 (All Bits Inverted)• +72 = 01001000• –72 = 10110111

Page 39: EENG 2710 Chapter 1

39

2’s Complement Form

57 = 0011 1001-57 = 1100 0110

+ 1 1100 0111

Page 40: EENG 2710 Chapter 1

40

Signed Binary Addition (8-Bit)

Signed Addition Positive (S = 0) +30 = 00011110 +75 = 01001011 105 01101001

Page 41: EENG 2710 Chapter 1

41

Subtraction with 1’s Complement• Add the 1’s Complement and then Carry.

• Uses an End around carry addition method.1111 0000

1 1110 0000 1

65) Comp s(1' 1110 1011 65)( 0001 0100 65 -0000 0101 80)( 0000 0101 80

(80 – 65)

Page 42: EENG 2710 Chapter 1

42

2’s Complement Subtraction• Add 2’s Complement to Minuend.

Discord Carry Bit From Results

(80 – 65)

Page 43: EENG 2710 Chapter 1

43

2’s Complement Subtraction20010 – 510 = 19510

(Use 16 bit word) 20010 = 00000000110010002

510 = 00000000000001012

-510 = 11111111111110102 = 1’s complement + 1 11111111111110112

00000000110010002

+ 11111111111110112

100000000110000112 = 00000000110000112 = 19510

Page 44: EENG 2710 Chapter 1

44

Negative Results

• If the True-Magnitude Form is used for subtraction, the results are incorrect.

• If the result is from 1’s or 2’s Complement and the result is negative (S = 1), the magnitude is found by taking the complement of the result.

Page 45: EENG 2710 Chapter 1

45

Negative Result Example

Thus, = -1510

Page 46: EENG 2710 Chapter 1

46

More Binary Addition

Page 47: EENG 2710 Chapter 1

47

More Binary Subtraction

Page 48: EENG 2710 Chapter 1

48

Binary Multiplication

Page 49: EENG 2710 Chapter 1

49

Binary Division

Page 50: EENG 2710 Chapter 1

50

Range of Signed Numbers

• Range of Positive Numbers is 0 to 2n – 1 for a number with n magnitude bits.

• Range of Negative Numbers is –1 to –2n for a number with n magnitude bits.

• 8-Bit Example:8-Bit Number Range is –2n x +2n – 1

or –128 to +127

Page 51: EENG 2710 Chapter 1

51

Sign Bit Overflow

• Overflow:– An erroneous carry into the sign bit of a

signed binary number– Results from a sum or difference that is

larger than can be represented by the magnitude bits.

• Results in a False Positive or False Negative Number.

Page 52: EENG 2710 Chapter 1

52

False Negative Overflow

• Addition of two 8-Bit Positive Numbers:

• Two positive numbers added with a result greater than the range of +127 for 8-bit numbers causes an overflow.

(False) Negative is Result 1011 1010

0000 0110 961011 0100 75

Page 53: EENG 2710 Chapter 1

53

False Positive Overflow• Addition of two 8-Bit Negative Numbers:

• Two Negative numbers were added to produce a False Positive Result due to overflowing the negative range of 8-bit numbers (0 to –128).

(False) Positive is Result 1111 0110

1111 1011 650000 1011 80

Page 54: EENG 2710 Chapter 1

54

Hexadecimal Addition

• Similar to decimal addition with a range of digits of 0 to 9 and A to F.

• Examples: F + 1 = 10 F + F = 1E F + F + 1 = 1F

Page 55: EENG 2710 Chapter 1

55

414FH Hex 4)(15) ( 1) 4)( (

9)(12) 1)(10)( ( (11)(3) 6) 2)( (

1 1 Carry

5)(16)(20)(1 (3)

9)(12) 1)(10)( ( 1A9CH3) (11)( 6) 2)( ( 26B3H

Equivalent Decimal Hex

Hexadecimal Addition

• For sums greater than 15, subtract 16 and carry 1 to the next position.

Page 56: EENG 2710 Chapter 1

56

Hexadecimal Subtraction

C17H Hex 7) ( (1) 0)(12)(

(12) (9) (10) (1) - 3) (10)(16 6) (1)(16

1 1 Borrow position. previous the from

)(16 10Hborrow digit, tsignifican least the subtract To(12)(1)(10)(9) 1A9CH(3)(2)(6)(11) 26B3H

Equivalent Decimal Hex

10

Page 57: EENG 2710 Chapter 1

57

Hexadecimal Subtraction

2F00H – 4000HConvert 4000H to hexadecimal equivalent of 2’s complement: FFFF 4000 BFFF + 1 C000Add numbers: 2F00 + C000 EF00H

Page 58: EENG 2710 Chapter 1

58

Hexadecimal Subtraction2F00H – 4000H

a. Converting 4000 to binary = 0100 0000 0000 0000 b. Take 1’s complement = 1011 1111 1111 1111c. Take 2’s complement = +1 +1 +1 +1 1100 0000 0000 0000d. Change to Hexadecimal = C000H e. Add numbers: 2F00 + C000 EF00H

Page 59: EENG 2710 Chapter 1

59

More Hexadecimal Addition

Page 60: EENG 2710 Chapter 1

60

More Hexadecimal Subtraction

Page 61: EENG 2710 Chapter 1

61

Hexadecimal Multiplication

Page 62: EENG 2710 Chapter 1

62

Hexadecimal Division

Page 63: EENG 2710 Chapter 1

63

Octal Addition

Page 64: EENG 2710 Chapter 1

64

Octal Subtraction

Page 65: EENG 2710 Chapter 1

65

Octal Multiplication

Page 66: EENG 2710 Chapter 1

66

Octal Division

Page 67: EENG 2710 Chapter 1

67

Excess 8 code

Page 68: EENG 2710 Chapter 1

68

BCD Codes

• BCD Code (Binary-Coded Decimal): A code used to represent each decimal digit of a number by a 4-Bit Binary Value.

• Valid Digits for 0 to 9 are 0000 to 1001.– The binary codes 1010 to 1111 are invalid

• Called an 8421 Code due to the decimal weight of each bit position.

Page 69: EENG 2710 Chapter 1

69

BCD Examples

Each digit is a 4-Bit Binary group:(84)10 = 1000 0100

(4987)10 = 0100 1001 1000 0111BCD

Page 70: EENG 2710 Chapter 1

70

Gray Code• A binary code that progresses so that only one

bit changes between two successive codes. 000 001

011 010 110 111 101 100

Page 71: EENG 2710 Chapter 1

71

How to build a 4-bit Gray Code Table(A binary code that progresses so that only one bit changes between two

successive codes.)

3-bit Gray code0 0 00 0 10 1 10 1 01 1 01 1 11 0 11 0 0

4-bit Gray code0 0 0 00 0 0 10 0 1 10 0 1 00 1 1 00 1 1 10 1 0 10 1 0 01 1 0 01 1 0 11 1 1 11 1 1 01 0 1 01 0 1 11 0 0 11 0 0 0

2-bit Gray code0 00 11 11 0

Page 72: EENG 2710 Chapter 1

72

4-bit Gray Code Table 4-bit Gray Code Sequence

Q3 Q2 Q1 Q00 0 0 00 0 0 10 0 1 10 0 1 00 1 1 00 1 1 10 1 0 10 1 0 01 1 0 01 1 0 11 1 1 11 1 1 01 0 1 01 0 1 11 0 0 11 0 0 0

Page 73: EENG 2710 Chapter 1

73

A Gray Code Disk

Page 74: EENG 2710 Chapter 1

74

ASCII Code

• American Standard Code for Information Interchange.

• A seven-bit alphanumeric code used to represent text letters, numerals, punctuation, and special controls.

• An expanded 8-bit form is becoming more widespread.

Page 75: EENG 2710 Chapter 1

75

ASCII Code