Princess Sumaya Univ. Computer Engineering Dept. د. بســام كحـالــه Dr. Bassam Kahhaleh
Princess Sumaya Univ. Computer Engineering Dept. Chapter 1:
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 2 / 45 Digital Systems Discrete Data ●Examples: ♦ 26 letters of the alphabet (A, B … etc) ♦ 10 decimal digits (0, 1, 2 … etc) ●Combine together ♦ Words are made of letters (University … etc) ♦ Numbers are made of digits (4241 … etc) Binary System ●Only ‘0’ and ‘1’ digits ●Can be easily implemented in electronic circuits AnalogDiscrete
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 3 / 45 Decimal Number System Base (also called radix) = 10 ●10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } Digit Position ●Integer & fraction Digit Weight ●Weight = (Base) Position Magnitude ●Sum of “Digit x Weight” Formal Notation d 2 *B 2 +d 1 *B 1 +d 0 *B 0 +d -1 *B -1 +d -2 *B -2 (512.74) 10
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 4 / 45 Octal Number System Base = 8 ●8 digits { 0, 1, 2, 3, 4, 5, 6, 7 } Weights ●Weight = (Base) Position Magnitude ●Sum of “Digit x Weight” Formal Notation /8641/ * * * * *8 - 2 =( ) 10 (512.74) 8
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 5 / 45 Binary Number System Base = 2 ●2 digits { 0, 1 }, called b inary dig its or “bits” Weights ●Weight = (Base) Position Magnitude ●Sum of “Bit x Weight” Formal Notation Groups of bits 4 bits = Nibble 8 bits = Byte /241/ * * * * *2 - 2 =(5.25) 10 (101.01)
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 6 / 45 Hexadecimal Number System Base = 16 ●16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F } Weights ●Weight = (Base) Position Magnitude ●Sum of “Digit x Weight” Formal Notation / /256 1E57A 1 * * * * *16 -2 =( ) 10 (1E5.7A) 16
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 7 / 45 The Power of 2 n2n2n 02 0 = = = = = = = =128 n2n2n 82 8 = = = = = =1M =1G =1T Mega Giga Tera Kilo
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 8 / 45 Addition Decimal Addition = Ten ≥ Base Subtract a Base 11Carry
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 9 / 45 Binary Addition Column Addition ≥ (2) = 61 = 23 = 84
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 10 / 45 Binary Subtraction Borrow a “Base” when needed − = (10) = 77 = 23 = 54
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 11 / 45 Binary Multiplication Bit by bit x
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 12 / 45 Number Base Conversions Decimal (Base 10) Octal (Base 8) Binary (Base 2) Hexadecimal (Base 16) Evaluate Magnitude
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 13 / 45 Decimal (Integer) to Binary Conversion DD ivide the number by the ‘Base’ (=2) TT ake the remainder (either 0 or 1) as a coefficient TT ake the quotient and repeat the division Example: ( 13 ) 10 QuotientRemainder Coefficient Answer: (13) 10 = (a 3 a 2 a 1 a 0 ) 2 = (1101) 2 MSB LSB 13 / 2 = 61 a 0 = 1 6 / 2 = 30 a 1 = 0 3 / 2 = 11 a 2 = 1 1 / 2 = 01 a 3 = 1
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 14 / 45 Decimal (Fraction) to Binary Conversion MM ultiply the number by the ‘Base’ (=2) TT ake the integer (either 0 or 1) as a coefficient TT ake the resultant fraction and repeat the division Example: ( ) 10 IntegerFraction Coefficient Answer: (0.625) 10 = (0.a -1 a -2 a -3 ) 2 = (0.101) 2 MSB LSB * 2 = * 2 = 0. 5 a -2 = * 2 = 1. 0 a -3 = 1 a -1 = 1
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 15 / 45 Decimal to Octal Conversion Example: ( 175 ) 10 QuotientRemainder Coefficient Answer: (175) 10 = (a 2 a 1 a 0 ) 8 = (257) / 8 = 217 a 0 = 7 21 / 8 = 25 a 1 = 5 2 / 8 = 02 a 2 = 2 Example: ( ) 10 IntegerFraction Coefficient Answer: (0.3125) 10 = (0.a -1 a -2 a -3 ) 8 = (0.24) * 8 = * 8 = 4. 0 a -2 = 4 a -1 = 2
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 16 / 45 Binary − Octal Conversion 8 = 2 3 Each group of 3 bits represents an octal digit OctalBinary Example: ( ) 2 ( ) 8 Assume Zeros Works both ways (Binary to Octal & Octal to Binary)
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 17 / 45 Binary − Hexadecimal Conversion 16 = 2 4 Each group of 4 bits represents a hexadecimal digit HexBinary A1 0 B C D E F1 1 Example: ( ) 2 ( ) 16 Assume Zeros Works both ways (Binary to Hex & Hex to Binary)
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 18 / 45 Octal − Hexadecimal Conversion Convert to Binary as an intermediate step Example: ( ) 2 ( ) 16 Assume Zeros Works both ways (Octal to Hex & Hex to Octal) ( ) 8 Assume Zeros
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 19 / 45 Decimal, Binary, Octal and Hexadecimal DecimalBinaryOctalHex A B C D E F
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 20 / 45 Complements 11 ’s Complement (Diminished Radix Complement) ●A●All ‘0’s become ‘1’s ●A●All ‘1’s become ‘0’s Example ( ) 2 ( ) 2 If you add a number and its 1’s complement …
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 21 / 45 Complements 22 ’s Complement (Radix Complement) ●T●Take 1’s complement then add 1 ●T●Toggle all bits to the left of the first ‘1’ from the right Example: Number: 1’s Comp.: OR
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 22 / 45 Negative Numbers CC omputers Represent Information in ‘0’s and ‘1’s ●‘●‘+’ and ‘−’ signs have to be represented in ‘0’s and ‘1’s 33 Systems ●S●Signed Magnitude ●1●1’s Complement ●2●2’s Complement All three use the left-most bit to represent the sign: ♦‘♦‘ 0’ positive ♦‘♦‘ 1’ negative
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 23 / 45 Signed Magnitude Representation MM agnitude is magnitude, does not change with sign (+3) 10 ( ) 2 (−3) 10 ( ) 2 CC an’t include the sign bit in ‘Addition’ (+3) (−3) (−6) 10 SignMagnitude SMagnitude (Binary)
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 24 / 45 1’s Complement Representation PP ositive numbers are represented in “Binary” NN egative numbers are represented in “1’s Comp.” (+3) 10 (0 011) 2 (−3) 10 (1 100) 2 TT here are 2 representations for ‘0’ (+0) 10 (0 000) 2 (−0) 10 (1 111) 2 0Magnitude (Binary) 1Code (1’s Comp.)
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 25 / 45 1’s Complement Range 4-Bit Representation 2 4 = 16 Combinations − 7 ≤ Number ≤ + 7 − ≤ Number ≤ +2 3 − 1 n-Bit Representation −2 n−1 +1 ≤ Number ≤ +2 n−1 − 1 Decimal1’s Comp − 01 1 − − − − − 51 0 − −
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 26 / 45 2’s Complement Representation PP ositive numbers are represented in “Binary” NN egative numbers are represented in “2’s Comp.” (+3) 10 (0 011) 2 (−3) 10 (1 101) 2 TT here is 1 representation for ‘0’ (+0) 10 (0 000) 2 (−0) 10 (0 000) 2 0Magnitude (Binary) 1Code (2’s Comp.) 1’s Comp
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 27 / 45 2’s Complement Range 4-Bit Representation 2 4 = 16 Combinations − 8 ≤ Number ≤ + 7 −2 3 ≤ Number ≤ − 1 n-Bit Representation −2 n−1 ≤ Number ≤ + 2 n−1 − 1 Decimal2’s Comp − 11 1 − − − − − 61 0 − −
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 28 / 45 Number Representations 4-Bit Example Unsigned Binary Signed Magnitude 1’s Comp.2’s Comp. Range0 ≤ N ≤ 15-7 ≤ N ≤ ≤ N ≤ +7 Positive Binary Negative X Binary1’s Comp.2’s Comp
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 29 / 45 Binary Subtraction Using 1’s Comp. Addition CC hange “Subtraction” to “Addition” II f “Carry” = 1 then add it to the LSB, and the result is positive (in Binary) II f “Carry” = 0 then the result is negative (in 1’s Comp.) (5) 10 – (1) 10 (+5) 10 + (-1) (5) 10 – (6) 10 (+5) 10 + (-6) − 1 1
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 30 / 45 Binary Subtraction Using 2’s Comp. Addition CC hange “Subtraction” to “Addition” II f “Carry” = 1 ignore it, and the result is positive (in Binary) II f “Carry” = 0 then the result is negative (in 2’s Comp.) (5) 10 – (1) 10 (+5) 10 + (-1) (5) 10 – (6) 10 (+5) 10 + (-6) − 1
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 31 / 45 Binary Codes GG roup of n bits ●U●Up to 2 n combinations ●E●Each combination represents an element of information BB inary Coded Decimal (BCD) ●E●Each Decimal Digit is represented by 4 bits ●(●(0 – 9) Valid combinations ●(●(10 – 15) Invalid combinations DecimalBCD
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 32 / 45 BCD Addition OO ne decimal digit + one decimal digit ●I●If the result is 1 decimal digit ( ≤ 9 ), then it is a simple binary addition Example: ●I●If the result is two decimal digits ( ≥ 10 ), then binary addition gives invalid combinations Example:
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 33 / 45 BCD Addition II f the binary result is greater than 9, correct the result by adding Two Decimal Digits Multiple Decimal Digits
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 34 / 45 Gray Code OO ne bit changes from one code to the next code DD ifferent than Binary DecimalGray Binary
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 35 / 45 ASCII Code American Standard Code for Information Interchange Info7-bit Code A B Z a b ?
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 36 / 45 Error Detecting Codes PP arity One bit added to a group of bits to make the total number of ‘1’s (including the parity bit) even or odd ●E●Even ●O●Odd GG ood for checking single-bit errors bit Example 7-bit Example
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 37 / 45 Binary Logic Operators ●NOT If ‘x’ = 0thenNOT ‘x’ = 1 If ‘x’ = 1thenNOT ‘x’ = 0 ●AND If ‘x’ = 1 AND ‘y’ = 1then‘z’ = 1 Otherwise‘z’ = 0 ●OR If ‘x’ = 1 OR ‘y’ = 1then‘z’ = 1 Otherwise‘z’ = 0
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 38 / 45 Binary Logic Truth Tables, Boolean Expressions, and Logic Gates xyz xyz xz ANDORNOT z = x y = x yz = x + yz = x = x’
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 39 / 45 Logic Signals BB inary ‘0’ is represented by a “low” voltage (range of voltages) BB inary ‘1’ is represented by a “high” voltage (range of voltages) TT he “voltage ranges” guard against noise of binary signalsExample
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 40 / 45 Switching Circuits ANDOR
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 41 / 45 Homework Mano ●Chapter 1 ♦ 1-2 ♦ 1-7 ♦ 1-9 ♦ 1-10 ♦ 1-11 ♦ 1-16 ♦ 1-18 ♦ 1-20 ♦ 1-24(a) ♦ 1-29 Write your family name in ASCII with odd parity Decode the following ASCII string (with MSB = parity): Is the parity even or odd?
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 42 / 45 Homework Mano 1-2What is the exact number of bytes in a system that contains (a) 32K byte, (b) 64M byte, and (c) 6.4G byte? 1-7Express the following numbers in decimal: ( ) 2, (16.5) 16, and (26.24) Convert the hexadecimal number 68BE to binary and then from binary convert it to octal. 1-10Convert the decimal number 345 to binary in two ways: (a) convert directly to binary, (b) convert first to hexadecimal, then from hexadecimal to binary. Which method is faster?
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 43 / 45 Homework 1-11Do the following conversion problems: (a) Convert decimal to binary. (b) Calculate the binary equivalent of 1/3 out to 8 places. Then convert from binary to decimal. How close is the result to 1/3? (c) Convert the binary result in (b) into hexadecimal. Then convert the result to decimal. Is the answer the same? 1-16Obtain the 1’s and 2’s complements of the following binary numbers: (a) (b) (c) (d) (e)
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 44 / 45 Homework 1-18Perform subtraction on the following unsigned binary numbers using the 2’s-complement of the subtrahend. Where the result should be negative, 2’s complement it and affix a minus sign. (a) – (b) – (c) 1011 – (d) – Convert decimal +61 and +27 to binary using the signed- 2’s complement representation and enough digits to accommodate the numbers. Then perform the binary equivalent of (+27) + (– 61), (–27) + (+61) and (–27) + (–61). Convert the answers back to decimal and verify that they are correct.
Princess Sumaya University 4241 – Digital Logic Design Computer Engineering Dept. 45 / 45 Homework 1-24Represent decimal number 6027 in (a) BCD 1-29The following is a string of ASCII characters whose bit patterns have been converted into hexadecimal for compactness: 4A EF 68 6E 20 C4 EF E5. Of the 8 bits in each pair digit, the leftmost is a parity bit. The remaining bits are the ASCII code. (a) Convert to bit form and decode the ASCII (b) Determine the parity used: odd or even.