Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Systems and Logic Design

Similar presentations


Presentation on theme: "Digital Systems and Logic Design"— Presentation transcript:

1 Digital Systems and Logic Design

2 General Overview This chapter is Number Systems, Operations, and Codes. Decimal numbers Binary numbers Decimal-to-binary numbers Binary arithmetic 1’s and 2’s Complements of Binary numbers Signed number Arithmetic operations with signed numbers Hexadecimal Numbers Octal Numbers Binary Coded Decimal (BCD) Digital Codes and Parity Digital System Application

3 Chapter Objectives Convert the number between decimal and binary.
Apply arithmetic operation to binary numbers. Understand Binary Coded Decimal (BCD), Gray Code, ASCII

4 Decimal Numbers Decimal numbers has ten digits. (0, 1, 2, 3, …, 9)
The decimal numbering system has a base of 10 with each position weighted by a factor of 10:

5 Binary Numbers Binary numbers has two digits, 1 and 0.
The binary numbering system has a base of 2 with each position weight by a factor of 2.

6 Binary numbers: Example
10010 in binary is 1x24 + 0x23 + 0x22 + 1x21 + 0x20 = 18 Binary is the base 2 number system Most common in digital electronics Weight: Most Significant bit (MSB) Least Significant bit (LSB) 10010 MSB LSB

7 Integers and Fractional Parts
Binary numbers can contain fractional parts as well as integer parts # quantization error.

8 Conversion: Decimal to Binary (Method 1)
The decimal numbers is simply expressed as a sum of power of 2, and then 1s and 0s are written in the appropriate bit positions. 50 = = = 1x25 + 1x24 + 1x21 5010 = 322 = ?

9 Conversion: Decimal to Binary (Method 2)
Repeated division Quotient Remainder 50/2 = LSB 25/2 = 12/2 = 6/2 = 3/2 = 1/2 = MSB stop 50 =

10 Conversion: Binary to Decimal
The simplest way is to represent the binary number as anx2n a2x22 + a1x21 + a0x20 The conversion can be done by substituting the a’s with the given bits then multiplying and adding: = 1x25 + 1x24 + 1x21 = 50

11 Example Convert the binary whole number 100011012 to decimal
= 27 + 23 + 22 + 20 = = 14110

12 Example Convert the fractional binary number 0.10112 to decimal
= 2-1 + 2-3 + 2-4 + 2-6 = =

13 Example Convert the binary whole number 101.01012 to decimal
= = =

14 Conversion: Fractional to Binary
เลขทศนิยมฐานสิบเป็นเลขฐานสอง ผลบวกของค่าน้ำหนัก การคูณซ้ำด้วยสอง 0.782 = ผลบวกของค่าน้ำหนัก : การคูณซ้ำด้วยสอง : 0.782 = = ( ) 0.782 x 2 = 1.564 0.564 x 2 = 1.128 = 0.128 x 2 = 0.256 = 0.256 x 2 = 0.512 0.512 x 2 = 1.024

15 Binary Number Systems Unsigned Binary Code Signed Binary Codes
2’s Complement System BCD Code Excess Codes Floating-Point System

16 Unsigned Binary Code Given a number N in Unsigned Binary code, find the value of N in the decimal system Use series substitution method Given a number N in the decimal system, find the value of N in the Unsigned Binary Code. Use successive division method (for integer part) Use successive multiplication method (for fraction part)

17 Unsigned Binary Code Can’t do. Not enough bits. 2610 = 00011010
Example 1: Represent (26)10 in Unsigned Binary Code 2610 = Example 2: Represent (26)10 in Unsigned Binary Code using 8 bits. 2610 = Example 3: Represent (26)10 in Unsigned Binary Code using 4 bits. Can’t do. Not enough bits.

18 Unsigned Binary Code ( 4 bits)

19 Unsigned Binary Code [0, 2n-1]
The Unsigned Binary Code is used to represent positive integer numbers. What is the range of values that can be represented with n bits in the Unsigned Binary Code? [0, 2n-1] How many bits are required to represent a given number N? number of bits = smallest integer greater than or equal to log(N)

20 Unsigned Binary Code: Arithmetic & Logic Operations
Arithmetic Operations: Addition Subtraction Multiplication Division Logic Operations AND CONJUNCTION OR DISJUNCTION NOT NEGATION XOR EXCLUSIVE OR

21 Signed Binary Codes These are codes used to represent positive and negative numbers. Sign and Magnitude Code 1’s Complement Code 2’s Complement Code

22 Sign & Magnitude Code Sign & Mag. Code Decimal 01101 +13 11101 -13
The leftmost bit is the sign bit 0 for positive numbers 1 for negative numbers The remaining bits represent the magnitude of the number Example: Sign & Mag. Code Decimal

23 Sign &Magnitude (4 bits)
What is the range of values that can be represented in S&M code with n bits?

24 Sign&Magnitude Example 1: Represent (26)10 in Sign & Magnitude Code.
2610 = Example 2: Represent (26)10 in Sign & Magnitude Code using 8 bits 2610 = Example 3: Represent (26)10 in Sign & Magnitude Code using 5 bits. Need at least 6 bits.

25 Sign&Magnitude Example 1: Represent (-26)10 in Sign & Magnitude Code.
= = Example 2: Represent (-26)10 in Sign & Magnitude Code using 8 bits = = Example 3: Represent (-26)10 in Sign & Magnitude Code using 5 bits. Need at least 6 bits.

26 Binary Arithmetic Addition Subtraction Multiplication Division

27 Binary Addition Equation Recall decimal addition Binary addition

28 Example Add the following binary number:. (a) 10010011 + 01001011
Example Add the following binary number: (a) (b) 1 1 (a) 147 + 75 1 1 1 1 1 1 = 222 1 1 1 1 1 31 (b) + 7 = 3810 1 1 1

29 Binary Subtraction สมการทั่วไป : ตารางความจริงการลบ A0 < B0 ต้องการ
0 - 0 = 0  ผลลบ 0 ตัวยืม 0 0 - 1 = 1  ผลลบ 1 ตัวยืม 1 1 - 0 = 1  ผลลบ 1 ตัวยืม 0 1 - 1 = 0  ผลลบ 0 ตัวยืม 0 ตารางความจริงการลบ สมการทั่วไป : A0 B0 R0 B0ut A0 < B0 ต้องการ ตัวยืม R0 : ผลต่าง Bout : ตัวยืม

30

31 Binary Multiplication
A Basic Roles for Multiplication

32

33 Binary Division

34 1’s Complement Code Positive numbers: Negative numbers:
same as in unsigned binary code pad a 0 at the leftmost bit position Negative numbers: 1. Represent the magnitude of the number in unsigned binary system 2. pad a 0 at the leftmost bit position 3. complement every bit

35 1’s Complement Code Example: represent 2610 in 1’s complement code
2610 = Pad a 0: = Example: Represent (-26)10 in 1’s complement code. = 2. Pad a 0: 3. Complement: (-26)10 = (100101)1’s comp

36 1’s Complement Code Example: Represent (-26)10 in 1’s comp. code using 8 bits 1. Represent magnitude in unsigned binary using 8 bits 26 = 2. Complement every bit -2610 = ( ) 1’s comp

37 1’s Complement Code (4 bits)
What is the range of values that can be represented in S&M code with n bits? [ -(2 (n-1) -1) , 2(n-1) -1]

38 2’s Complement Code This is the code commonly used to represent integer numbers. Positive Numbers: same as in unsigned binary code pad with a 0 leftmost bit position Negative Numbers 1. represent magnitude in unsigned binary code 2. pad leftmost positions with 0s 3. complement every bit 4. add 1

39 2’s Complement Code Example 1: Represent 26 in 2’s complement code.
26 = Example 2: Represent 26 in 2’s complement code using 8 bits 26 = Example 3: Represent 26 in 2’s complement code using 5 bits Need at least 6 bits.

40 2’s Complement Code Example 3: Represent - 26 in 2’s comp. Code
= 2. Pad with a 0: 3. Complement: 4. Add 1: 100110

41 2’s Complement Code Example 4: Represent in 2’s comp. Code using 8 bits = 2. Pad 0s: 3. Complement: 4. Add 1:

42 2’s Complement Code More example: represent 65 in 2’s comp. Code.
65 = -65 =

43 Conversion from 2’s comp code to decimal code
How to convert a number in 2’s Comp. Code into the decimal code. There 2 cases: Case 1: If leftmost bit of the number is 0 => number is positive => conversion is the same as in unsigned binary code

44 Conversion from 2’s comp code to decimal code
Case 2: If leftmost bit is 1 => the number is negative step1: complement every bit step2: add 1 step3: convert result to decimal code using same method as in unsigned binary code. Answer = the negative of the result of step 3.

45 2’s Complement Code (4 bits)
Range of values with n bits: [ -2 (n-1), 2(n-1) -1]

46 1’s and 2’s Complement of Binary Numbers

47

48 Alternative Method to find 2’s Complement

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65 Hexadecimal Notation Hexadecimal system: base 16 There are 16 digits:
A B C D E F Each Hex digit represents a group of 4 bits (i.e. half of a byte) thru 1111 Generally used as shorthand notation for binary numbers => easier to read Binary: Decimal: Hex: 5 A E

66 Hexadecimal number

67 Hexadecimal number conversions

68

69

70

71

72 Addition in Hex.

73 Subtration in Hex.

74

75 Octal number

76

77

78

79

80 Binary Coded Decimal (BCD)
Decimal numbers are more natural to humans. Binary numbers are natural to computers. Quite expensive to convert between the two. If little calculation is involved, we can use some coding schemes for decimal numbers. One such scheme is BCD, also known as the 8421 code. Represent each decimal digit as a 4-bit binary code.

81 Binary Coded Decimal (BCD)
Some codes are unused, eg: (1010)BCD, (1011) BCD, …, (1111) BCD. These codes are considered as errors. Easy to convert, but arithmetic operations are more complicated. Suitable for interfaces such as keypad inputs and digital readouts. CS1104-2 Binary Coded Decimal (BCD)

82 Binary Coded Decimal (BCD)
Examples: (234)10 = ( )BCD (7093)10 = ( )BCD ( )BCD = (86)10 ( )BCD = (9472)10 Notes: BCD is not equivalent to binary. Example: (234)10 = ( )2 CS1104-2 Binary Coded Decimal (BCD)

83 BCD : Binary Coded Decimal

84

85

86

87 The Gray Code Unweighted (not an arithmetic code).
Only a single bit change from one code number to the next. Good for error detection. Q. How to generate 5-bit standard Gray code? Q. How to generate n-bit standard Gray code? CS1104-2 The Gray Code

88 The Gray Code 0000 0001 0100 0101 0111 0110 0010 0011 0001 0000 1100 1101 1111 1110 1010 1011 1001 1000 0001 0000 0011 0010 0010 0011 0001 0000 0110 0111 0101 0100 Generating 4-bit standard Gray code. CS1104-2 The Gray Code

89 The Gray Code sensors mis-aligned sensors Gray coded: 111  101
sensors mis-aligned sensors Gray coded: 111  101 Binary coded: 111  110  000 mis-aligned sensors CS1104-2 The Gray Code

90 Binary-to-Gray Code Conversion
Retain most significant bit. From left to right, add each adjacent pair of binary code bits to get the next Gray code bit, discarding carries. Example: Convert binary number to Gray code. (10110)2 = (11101)Gray CS1104-2 Binary-to-Gray Code Conversion

91 Gray-to-Binary Conversion
Retain most significant bit. From left to right, add each binary code bit generated to the Gray code bit in the next position, discarding carries. Example: Convert Gray code to binary. (11011)Gray = (10010)2 CS1104-2 Gray-to-Binary Conversion

92 Error Detection Codes Sometimes, it is not enough to do error detection. We may want to do error correction. Error correction is expensive. In practice, we may use only single-bit error correction. Popular technique: Hamming Code (not covered). CS1104-2 Error Detection Codes

93 Gray code

94 Binary to Gray Conversion

95

96 Gray to Binary

97

98 Other Decimal Codes Self-complementing codes: excess-3, , 2*421 codes. Error-detecting code: biquinary code (bi=two, quinary=five). CS1104-2 Other Decimal Codes

99 Self-Complementing Codes
Examples: excess-3, , 2*421 codes. The codes that represent the pair of complementary digits are complementary of each other. Excess-3 code 0: 0011 1: 0100 2: 0101 3: 0110 4: 0111 5: 1000 6: 1001 7: 1010 8: 1011 9: 1100 241: 758: CS1104-2 Self-Complementing Codes

100 Alphanumeric Codes Apart from numbers, computers also handle textual data. Character set frequently used includes: alphabets: ‘A’ .. ‘Z’, and ‘a’ .. ‘z’ digits: ‘0’ .. ‘9’ special symbols: ‘$’, ‘.’, ‘,’, ‘*’, … non-printable: SOH, NULL, BELL, … Usually, these characters can be represented using 7 or 8 bits. CS1104-2 Alphanumeric Codes

101 Alphanumeric Codes Two widely used standards:
ASCII (American Standard Code for Information Interchange) EBCDIC (Extended BCD Interchange Code) ASCII: 7-bit, plus a parity bit for error detection (odd/even parity). EBCDIC: 8-bit code. CS1104-2 Alphanumeric Codes

102 Alphanumeric Codes ASCII table: CS1104-2 Alphanumeric Codes

103 Error Detection Codes Errors can occur data transmission. They should be detected, so that re-transmission can be requested. With binary numbers, usually single-bit errors occur. Example: 0010 erroneously transmitted as 0011, or 0000, or 0110, or 1010. Biquinary code uses 3 additional bits for error-detection. For single-error detection, one additional bit is needed. CS1104-2 Error Detection Codes

104 Error Detection Codes Parity bit. Example: Odd parity.
Even parity: additional bit supplied to make total number of ‘1’s even. Odd parity: additional bit supplied to make total number of ‘1’s odd. Example: Odd parity. Parity bits CS1104-2 Error Detection Codes

105 Error Detection Codes Parity bit can detect odd number of errors but not even number of errors. Example: For odd parity numbers, 10011  (detected) 10011  (non detected) Parity bits can also be applied to a block of data: Column-wise parity Row-wise parity CS1104-2 Error Detection Codes

106 Error Detection Codes Sometimes, it is not enough to do error detection. We may want to do error correction. Error correction is expensive. In practice, we may use only single-bit error correction. Popular technique: Hamming Code (not covered). CS1104-2 Error Detection Codes

107 Alphanumeric Codes

108 ASCII

109

110 Parity Method for error checking

111

112 Put it together


Download ppt "Digital Systems and Logic Design"

Similar presentations


Ads by Google