Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems.

Similar presentations


Presentation on theme: "1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems."— Presentation transcript:

1 1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems

2 2 Uses 10 digits [ 0, 1, 2,... 9 ] Decimal Numbers In general: N =  N i x 10 i where N i  [0, 1, 2,...8, 9], where N i are the weights and the base of the number System, i.e., 10, is raised to the exponent i. Note: decimal fractions occur when i is negative 0.35 = 3 x 10 -1 + 5 x 10 -2 In general: N =  N i x 10 i where N i  [0, 1, 2,...8, 9], where N i are the weights and the base of the number System, i.e., 10, is raised to the exponent i. Note: decimal fractions occur when i is negative 0.35 = 3 x 10 -1 + 5 x 10 -2 Positional Number Notation Weight of digit determined by its position. Positional Number Notation Weight of digit determined by its position. Example: 246= 200 + 40 + 6 = 2 x 10 2 + 4 x 10 1 + 6 x 10 0

3 3 Binary Numbers Uses 2 digits [ 0 & 1 ] Example: 111001 2 = 100000 2 + 10000 2 + 1000 2 + 000 2 + 00 2 + 1 2 = 1 x 2 5 + 1 x 2 4 + 1 x 2 3 + 0 x 2 2 + 0 x 2 1 + 1 x 2 0 = 1 x 32 + 1 x 16 + 1 x 8 + 0 x 4 + 0 x 2 + 1 x 1 = 57 10 In general: N =  N i x 2 i where N i  [0, 1]. Note: binary fractions occur when i is negative 0.11 2 = 1x 2 -1 + 1 x 2 -2 = 0.5 10 + 0.25 10 = 0.75 10 In general: N =  N i x 2 i where N i  [0, 1]. Note: binary fractions occur when i is negative 0.11 2 = 1x 2 -1 + 1 x 2 -2 = 0.5 10 + 0.25 10 = 0.75 10 Positional Number Notation

4 4 Hexadecimal (Hex) Numbers Example: 89AB 16 = 8000 16 + 900 16 + A0 16 + B 16 = 8 x 16 3 + 9 x 16 2 + A x 16 1 + B x 16 0 = 8 x 4096 + 9 x 256 + 10 x 16 + 11 x 1 = 35243 10 Uses 16 digits [ 0, 1, 2,... 9, A, B, C, D, E, F ] In general: N =  N i x 16 i where N i  [0, 1, 2,..., 9, A, B, C, D, E, F]. Note: hexadecimal fractions occur when i is negative 0.9A 16 = 9 x 16 -1 + 10 x 16 -2 = 0.5625 10 + 0.0390625 10 = 0.6015625 10 In general: N =  N i x 16 i where N i  [0, 1, 2,..., 9, A, B, C, D, E, F]. Note: hexadecimal fractions occur when i is negative 0.9A 16 = 9 x 16 -1 + 10 x 16 -2 = 0.5625 10 + 0.0390625 10 = 0.6015625 10 Note: A - F represent the decimal values of 10 - 15, respectively. Positional Number Notation

5 5 Conversion Among Bases In general, with positional number notation and the known decimal weights for each position in any arbitrary base, it is easiest to convert other bases to decimal. This was demonstrated in each previous example where the decimal value was found using the equation for base B:  N i x B i where N i  [0, 1, 2,..., B-1] and substituting the equivalent decimal weight for the digits N i and the decimal value of B i. Conversion among the 2 n bases (binary, hexadecimal, octal, etc.) is most easily achieved by first converting to binary, regrouping into n bits (starting at the base point) and then converting the groups of bits into the proper digits.

6 6 Memorize this table!!! It makes conversions between hexadecimal and binary trivial Hexadecimal  Binary HexBinaryDecimal 00000 0 10001 1 20010 2 30011 3 4 0100 4 5 0101 5 6 0110 6 70111 7 81000 8 91001 9 A101010 B101111 C110012 D110113 E111014 F111115 HexBinaryDecimal 00000 0 10001 1 20010 2 30011 3 4 0100 4 5 0101 5 6 0110 6 70111 7 81000 8 91001 9 A101010 B101111 C110012 D110113 E111014 F111115 Example: convert 10011000111001101 2  hexadecimal Group by 4s, starting at the right  expand into 4 bit groups 1 0011 0001 1100 1101 2  1 3 1 C D 16 Example: convert 10011000111001101 2  hexadecimal Group by 4s, starting at the right  expand into 4 bit groups 1 0011 0001 1100 1101 2  1 3 1 C D 16

7 7 Decimal  Binary Example: 57  2 =28,remainder = 1 (binary number will end with 1) 28  2 =14,remainder = 0 14  2 =7,remainder = 0 7  2 =3,remainder = 1 3  2 =1,remainder = 1 1  2 =0,remainder = 1 (binary number will start with 1) Therefore, collecting the remainders, 57 10 = 111001 2 (((((0x2 + 1)x2 + 1)x2 + 1)x2 +0)x2 +0)x2 +1 = 1x32 + 1x16 + 1x8 + 0x4 + 0x2 + 1x1 = 57 (check: 32 + 16 + 8 + 0 + 0 + 1 = 57) Based on the remainders after dividing the decimal number by higher powers of 2. If the decimal number is even, the corresponding binary number will end in a 0, and if it is odd, the binary number will end in a 1, and so on. Based on the remainders after dividing the decimal number by higher powers of 2. If the decimal number is even, the corresponding binary number will end in a 0, and if it is odd, the binary number will end in a 1, and so on. Successive Division: Successive Division: an easy way to convert Decimal to Binary

8 8 Decimal  Hex Example: 35243 / 16=2202,remainder = 11  B(hex number will end with B) 2202 / 16=137,remainder = 10  A 137 / 16=8,remainder = 9 8 / 16 =0, remainder = 8(hex number will start with 8) Therefore, collecting the remainders, 35243 10 = 89AB 16 (check: 8 x 4096 + 9 x 256 +10 x 16 + 11 = 35243) Successive Division: Successive Division: an easy way to convert Decimal to Hexadecimal Based on the remainders after dividing the decimal number by higher powers of 16.

9 9 Hex  Decimal Example: BA89  B x 16 3 + A x 16 2 + 8 x 16 + 9 (CAUTION: mixed bases) = 11 x 4096 + 10 x 256 + 8 x 16 + 9 = 45056 + 2560 + 128 + 9 = 47753 We can check by converting back to hex: 47753 / 16 = 2984 + remainder, 9 2984 / 16 = 186 + remainder, 8 186 / 16 = 11 + remainder, 10  A 11 / 16 = 0 + remainder, 11  B  47753 10  BA89 16 Multiplication: Multiplication: an easy way to convert Hexadecimal to Decimal Multiply the hexadecimal weights by powers of 16.

10 10 Binary  Decimal Compare: 11010110 2  2 7 + 2 6 + 2 4 + 2 2 + 2 (exploiting the binary weights) = 128 + 64 + 16 + 4 + 2 = 214 10 11010110 2  D6 16  13 x 16 + 6 = 208 + 6 = 214 10 Multiplication: Multiplication: an easy way to convert Binary to Decimal We can multiple the binary weights by powers of 2. However, sometimes it is just as easy to convert the binary number to hexadecimal first and and then into decimal. We can multiple the binary weights by powers of 2. However, sometimes it is just as easy to convert the binary number to hexadecimal first and and then into decimal.

11 11 Computers have circuits that do binary arithmetic. You already know the rules for decimal addition and subtraction (how to handle sums, carries, differences, and borrows). Analogously, we develop the rules for binary addition and subtraction. Binary Arithmetic

12 12 95 10 9 x 10 1 +5 x 10 0 +16 10 +1 x 10 1 +6 x 10 0 10 x 10 1 +11 x 10 0 111 10  Decimal Addition Summary 11  Column carries 95 10 +16 10 111 10 Refresher = 1 x 10 2 + (0+1) x 10 1 + 1 x 10 0

13 13 Binary Addition 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0with a carry of 1 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0with a carry of 1 This table calculates the sum for pairs of binary numbers Also know as the Half Adder Table

14 14 Binary Addition with Carry carry addend augend sum 0+0+0= 0 0+0+1=1 0+1+0=1 0+1+1=0with a carry of 1 1+0+0=1 1+0+1=0 with a carry of 1 1+1+0=0 with a carry of 1 1+1+1=1with a carry of 1 carry addend augend sum 0+0+0= 0 0+0+1=1 0+1+0=1 0+1+1=0with a carry of 1 1+0+0=1 1+0+1=0 with a carry of 1 1+1+0=0 with a carry of 1 1+1+1=1with a carry of 1 This table shows all the possible sums for binary numbers with carries Also known as the Full Adder Table

15 15 Binary Addition (carries) 101 2 = 5 10 +11 2 = 3 10 = 8 10 Example: Add 5 and 3 in binary 1 1 1 0 1 10 10 1 102102 Similar to the decimal case

16 16 borrow = -1x10 1 9 1 5 10 95 = 9x10 1 + 5x10 0 = 9x10 1 + 15x10 0 -16 10 -16 = -1x10 1 + -6x10 0 = -1x10 1 + -6x10 0 -1 79 10 7x10 1 + 9x10 0 Decimal Subtraction Note: borrows are shown as explicit subtractions. Refresher

17 17 Binary Subtraction 0 - 0 = 0 0 - 1 = 1 with a borrow of 1 1 - 0 = 1 1 - 1 = 0 0 - 0 = 0 0 - 1 = 1 with a borrow of 1 1 - 0 = 1 1 - 1 = 0 This table calculates the difference for pairs of binary numbers Also known as the Half Subtractor Table

18 18 Binary Subtraction with Borrow minuend subtrahend borrow difference 0-0-0= 0 0-0-1=1 with a borrow of 1 0-1-0=1with a borrow of 1 0-1-1=0with a borrow of 1 1-0-0=1 1-0-1=0 1-1-0=0 1-1-1=1with a borrow of 1 minuend subtrahend borrow difference 0-0-0= 0 0-0-1=1 with a borrow of 1 0-1-0=1with a borrow of 1 0-1-1=0with a borrow of 1 1-0-0=1 1-0-1=0 1-1-0=0 1-1-1=1with a borrow of 1 This shows all the possibile differences for binary numbers with borrows Also known as the Full Subtractor Table

19 19 Binary Subtraction 101 2 =5 10 -11 2 =3 10 2 =2 10 Similar to the decimal case Example: Subtract 3 from 5 in binary 0 -1 (borrows) 1010 0 1

20 20 Number Systems Positive Positive numbers are same in most systems negative Major differences are in how negative numbers are represented Two major schemes: sign & magnitude two’s-complement For the examples assume a 4 bit machine word 16 different values can be represented roughly half are positive, half are negative Representation of Integers

21 21 Sign & Magnitude Representation Sign equals the High order bit:Sign equals the High order bit:0 = positive or zero (non-negative) 1 = negative Magnitude equals the three low order bits:Magnitude equals the three low order bits: 0 = 000 thru 7 = 111 n The number range =  7 for 4 bit numbers; for n bits,  2 n-1 -1 Two Representations for 0 (redundant & problematic) 0000 0111 0011 1011 1111 1110 1101 1100 1010 1001 1000 0110 0101 0100 0010 0001 +0+0+0+0 +1+1 +2+2 +3+3 +4+4 +5+5 +6+6 +7+7 -0-0-0-0 -1 -2-2 -3-3 -4-4 -5-5 -6-6 -7-7 0 100 = + 4 1 100 = - 4 + sign - sign 4 bit example

22 22 Sign & Magnitude 4 + 3 7 0100 0011 0111 -4 + (-3) -7 1100 1011 1111 Sign of the result: the same as the operands' sign (Don’t add sign bits) Operands have the same sign 4 + (-3) 1 0100 1011 0001 -4 + 3 1100 0011 1001 Sign of the result: the sign of operand with the larger magnitude Magnitude of the result: subtraction operation Operands have different signs Addition

23 23 Sign & Magnitude 4 - 3 1 0100 0011 0001 -4 - (-3) 1100 1011 1001 Sign of the result: the same as the operands' sign (Don’t subtract sign bits) Operands have the same sign 4 - (-3) 7 0100 1011 0111 -4 - 3 -7 1100 0011 1111 Sign of the result: the sign of operand with the larger magnitude Magnitude of the result: addition operation Operands have different signs Subtraction

24 24

25 25

26 26

27


Download ppt "1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems."

Similar presentations


Ads by Google