1.14k likes | 1.51k Views
Digital Systems and Logic Design. 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
E N D
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
Chapter Objectives • Convert the number between decimal and binary. • Apply arithmetic operation to binary numbers. • Understand Binary Coded Decimal (BCD), Gray Code, ASCII
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:
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.
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
Integers and Fractional Parts • Binary numbers can contain fractional parts as well as integer parts # quantization error.
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. 322 = ? 50 = 32 + 18 = 32 + 16 + 2 = 1x25 + 1x24 + 1x21 5010 = 1100102
Conversion: Decimal to Binary(Method 2) • Repeated division Quotient Remainder 50/2 = 25 0 LSB 25/2 = 12 1 12/2 = 6 0 6/2 = 3 0 3/2 = 1 1 1/2 = 0 1 MSB stop 50 = 110010
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: 110010 = 1x25 + 1x24 + 1x21 = 50
Example Convert the binary whole number 100011012 to decimal 100011012 = 27 + 23 + 22 + 20 = 128 + 8 + 4 + 1 = 14110
Example Convert the fractional binary number 0.10112 to decimal 2-1 + 2-6 0.1011012 = 2-3 + 2-4 + = 0.5 + 0.125 + 0.0625 = 0.687510
ExampleConvert the binary whole number 101.01012 to decimal 101.01012 = 22 + 20 + 2-2 + 2-4 = 4 + 1 +0.25 + 0.125 + 0.0625 = 5.437510
Conversion: Fractional to Binary • เลขทศนิยมฐานสิบเป็นเลขฐานสอง • ผลบวกของค่าน้ำหนัก • การคูณซ้ำด้วยสอง 0.782 = 0.110012 ผลบวกของค่าน้ำหนัก : การคูณซ้ำด้วยสอง : 0.782 = 0.5 + 0.25 + 0.03125 = (0.78125) 0.782 x 2 = 1.564 0.564 x 2 = 1.128 = 2-1 + 2-2 + 2-5 0.128 x 2 = 0.256 = 0.110012 0.256 x 2 = 0.512 0.512 x 2 = 1.024
Binary Number Systems • Unsigned Binary Code • Signed Binary Codes • 2’s Complement System • BCD Code • Excess Codes • Floating-Point System
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)
Unsigned Binary Code • Example 1: Represent (26)10 in Unsigned Binary Code 2610 = 11010 • Example 2: Represent (26)10 in Unsigned Binary Code using 8 bits. 2610 = 00011010 • Example 3:Represent (26)10 in Unsigned Binary Code using 4 bits. Can’t do. Not enough bits.
Unsigned Binary Code • 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)
Unsigned Binary Code: Arithmetic & Logic Operations • Arithmetic Operations: • Addition • Subtraction • Multiplication • Division • Logic Operations • AND CONJUNCTION • OR DISJUNCTION • NOT NEGATION • XOR EXCLUSIVE OR
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
Sign & Magnitude Code • 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. CodeDecimal 01101 +13 11101 -13 00101 +5 10101 -5
Sign &Magnitude (4 bits) What is the range of values that can be represented in S&M code with n bits?
Sign&Magnitude • Example 1: Represent (26)10 in Sign & Magnitude Code. 2610 = 011010 • Example 2: Represent (26)10 in Sign & Magnitude Code using 8 bits 2610 = 0001 1010 • Example 3: Represent (26)10 in Sign & Magnitude Code using 5 bits. • Need at least 6 bits.
Sign&Magnitude • Example 1: Represent (-26)10 in Sign & Magnitude Code. • 26 = 11010 • -2610 = 111010 • Example 2: Represent (-26)10 in Sign & Magnitude Code using 8 bits • 26 = 00011010 • - 2610 = 10011010 • Example 3: Represent (-26)10 in Sign & Magnitude Code using 5 bits. • Need at least 6 bits.
Binary Arithmetic Addition Subtraction Multiplication Division
Binary Addition • Equation Recall decimal addition Binary addition
Example Add the following binary number: (a) 10010011 + 01001011 (b) 00011111 + 00000111 (a) 1 0 0 1 0 0 1 1 + 0 1 0 0 1 0 1 1 1 1 147 + 75 1 1 0 1 1 1 1 0 = 222 1 1 1 1 1 31 (b) 0 0 0 1 1 1 1 1 + 0 0 0 0 0 1 1 1 + 7 = 3810 0 0 1 0 0 1 1 0
Binary Subtraction 0 - 0 = 0 ผลลบ0ตัวยืม0 0 - 1 = 1 ผลลบ1ตัวยืม 1 1 - 0 = 1 ผลลบ1ตัวยืม0 1 - 1 = 0 ผลลบ0ตัวยืม0 ตารางความจริงการลบ สมการทั่วไป : A0 B0 R0 B0ut 0 0 0 0 0 1 1 1 1 0 1 0 1 1 0 0 A0 < B0 ต้องการ ตัวยืม R0 : ผลต่าง Bout : ตัวยืม
Binary Multiplication A Basic Roles for Multiplication
1’s Complement Code • Positive numbers: • same as in unsigned binary code • pad a 0 at the leftmost bit position • Negative numbers: 1. Represent themagnitudeof the number in unsigned binary system 2. pad a 0 at the leftmost bit position 3. complement every bit
1’s Complement Code • Example: represent 2610 in 1’s complement code • 2610 = 11010 • Pad a 0: = 011010 • Example: Represent (-26)10 in 1’s complement code. 1. 26= 11010 2. Pad a 0: 011010 3. Complement: 100101(-26)10 = (100101)1’s comp
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 = 0001 1010 2. Complement every bit 11100101 -2610 = (1110 0101) 1’s comp
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]
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
2’s Complement Code • Example 1: Represent 26 in 2’s complement code. 26 = 011010 • Example 2: Represent 26 in 2’s complement code using 8 bits 26 = 00011010 • Example 3: Represent 26 in 2’s complement code using 5 bits • Need at least 6 bits.
2’s Complement Code • Example 3: Represent - 26 in 2’s comp. Code 1. +26 = 11010 2. Pad with a 0: 011010 3. Complement: 100101 4. Add 1: + 1 --------------- 100110
2’s Complement Code • Example 4: Represent - 26 in 2’s comp. Code using 8 bits 1. +26 = 11010 2. Pad 0s: 00011010 3. Complement: 11100101 4. Add 1: + 1 --------------- 11100110
2’s Complement Code • More example: represent 65 in 2’s comp. Code. • 65 = (0100 0001)2’s comp • Represent - 65 in 2’s comp • 65 = 0100 0001 • -65 = 1011 1111
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
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.
2’s Complement Code (4 bits) Range of values with n bits: [ -2 (n-1), 2(n-1) -1]