1 CSE-221 Digital Logic Design (DLD) Lecture-1: Digital Systems & Number Systems
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 x 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 x Positional Number Notation Weight of digit determined by its position. Positional Number Notation Weight of digit determined by its position. Example: 246= = 2 x x x 10 0
3 Binary Numbers Uses 2 digits [ 0 & 1 ] Example: = = 1 x x x x x x 2 0 = 1 x x x x x x 1 = In general: N = N i x 2 i where N i [0, 1]. Note: binary fractions occur when i is negative = 1x x 2 -2 = = In general: N = N i x 2 i where N i [0, 1]. Note: binary fractions occur when i is negative = 1x x 2 -2 = = Positional Number Notation
4 Hexadecimal (Hex) Numbers Example: 89AB 16 = A B 16 = 8 x x A x B x 16 0 = 8 x x x x 1 = 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 x = = 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 x = = Note: A - F represent the decimal values of , respectively. Positional Number Notation
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 Memorize this table!!! It makes conversions between hexadecimal and binary trivial Hexadecimal Binary HexBinaryDecimal A B C D E F HexBinaryDecimal A B C D E F Example: convert hexadecimal Group by 4s, starting at the right expand into 4 bit groups C D 16 Example: convert hexadecimal Group by 4s, starting at the right expand into 4 bit groups C D 16
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, = (((((0x2 + 1)x2 + 1)x2 + 1)x2 +0)x2 +0)x2 +1 = 1x32 + 1x16 + 1x8 + 0x4 + 0x2 + 1x1 = 57 (check: = 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 Decimal Hex Example: / 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, = 89AB 16 (check: 8 x x x = 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 Hex Decimal Example: BA89 B x A x x (CAUTION: mixed bases) = 11 x x x = = We can check by converting back to hex: / 16 = remainder, / 16 = remainder, / 16 = 11 + remainder, 10 A 11 / 16 = 0 + remainder, 11 B BA89 16 Multiplication: Multiplication: an easy way to convert Hexadecimal to Decimal Multiply the hexadecimal weights by powers of 16.
10 Binary Decimal Compare: (exploiting the binary weights) = = D6 16 13 x = = 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 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
x x x x x x Decimal Addition Summary 11 Column carries Refresher = 1 x (0+1) x x 10 0
13 Binary Addition = = = = 0with a carry of = = = = 0with a carry of 1 This table calculates the sum for pairs of binary numbers Also know as the Half Adder Table
14 Binary Addition with Carry carry addend augend sum 0+0+0= = = =0with a carry of = =0 with a carry of =0 with a carry of =1with a carry of 1 carry addend augend sum 0+0+0= = = =0with a carry of = =0 with a carry of =0 with a carry of =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 Binary Addition (carries) = = 3 10 = 8 10 Example: Add 5 and 3 in binary Similar to the decimal case
16 borrow = -1x = 9x x10 0 = 9x x = -1x x10 0 = -1x x x x10 0 Decimal Subtraction Note: borrows are shown as explicit subtractions. Refresher
17 Binary Subtraction = = 1 with a borrow of = = = = 1 with a borrow of = = 0 This table calculates the difference for pairs of binary numbers Also known as the Half Subtractor Table
18 Binary Subtraction with Borrow minuend subtrahend borrow difference 0-0-0= =1 with a borrow of =1with a borrow of =0with a borrow of = = = =1with a borrow of 1 minuend subtrahend borrow difference 0-0-0= =1 with a borrow of =1with a borrow of =0with a borrow of = = = =1with a borrow of 1 This shows all the possibile differences for binary numbers with borrows Also known as the Full Subtractor Table
19 Binary Subtraction = = =2 10 Similar to the decimal case Example: Subtract 3 from 5 in binary 0 -1 (borrows)
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 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) = = sign - sign 4 bit example
22 Sign & Magnitude (-3) Sign of the result: the same as the operands' sign (Don’t add sign bits) Operands have the same sign 4 + (-3) Sign of the result: the sign of operand with the larger magnitude Magnitude of the result: subtraction operation Operands have different signs Addition
23 Sign & Magnitude (-3) Sign of the result: the same as the operands' sign (Don’t subtract sign bits) Operands have the same sign 4 - (-3) Sign of the result: the sign of operand with the larger magnitude Magnitude of the result: addition operation Operands have different signs Subtraction
24
25
26