Professional Documents
Culture Documents
Text books
Digital Logic and Computer Design by Morris Mano Digital Fundamentals by Floyd
Grading
Digital System
Analog electronics deals with non-discrete values Digital electronics deals with discrete values
Digital Electronics
Digital Electronics represents information (0, 1) with
only two discrete values. Ideally no voltage (e.g., 0v) represents a 0 and full source voltage (e.g., 5v) represents a 1 Realistically low voltage (e.g., <1v) represents a 0 and high voltage (e.g., >4v) represents a 1 We achieve these discrete values by using switches. We use transistor switches, which operates at high speed, electronically, a small in size.
Reproducibility Not effected by noise means quality Ease of design Data protection Programmable Speed Economy
B3 0 0 0 0 0 0 0 0 1 1
B2 0 0 0 0 1 1 1 1 0 0
B1 0 0 1 1 0 0 1 1 0 0
B0 0 1 0 1 0 1 0 1 0 1
Val 0 1 2 3 4 5 6 7 8 9
Digital Revolution
Digital systems started back in 1940s. Digital systems cover all areas of life: still pictures digital video digital audio telephone traffic lights Animation
Number Systems
13
Binary Numbers
Strings of binary digits (bits) One bit can store a number from 0 to 1 n bits can store numbers from 0 to 2n
14
Binary Powers of 2
Positional representation Each digit represents a power of 2
So 101 binary is 1 22 + 0 21 + 1 20 or 14 + 02 + 11=5
15
16
128 + 0 + 0 + 16 + 8 + 4 + 0 + 0 = 156
17
Decimal to Binary
A little more work than binary to decimal Some examples 3 = 2 + 1 = 11 (thats 121 + 120) 5 = 4 + 1 = 101 (thats 122 + 021 + 120)
18
19
32 is too large, so use 16 Binary 10000 Decimal 28 16 = 12 Next is 8 Binary 11000 Decimal 12 8 = 4 Next is 4 Binary 11100 Decimal 4 4 = 0
7 27 128 6 26 64 5 25 32 4 24 16 3 23 8 2 22 4 1 21 2 0 20 1
20
Hexadecimal
Strings of 0s and 1s too hard to write Use base-16 or hexadecimal 4 bits
Dec 0 1 2 3 4 5 6 7
Hex 0 1 2 3 4 5 6 7
Dec 8 9 10 11 12 13 14 15
Hex 8 9 ? ? ? ? ? ?
21
Hexadecimal
Letters to represent 10-15
Dec 0 1 2 3 4 5 6 7
Hex 0 1 2 3 4 5 6 7
Dec 8 9 10 11 12 13 14 15
Hex 8 9 a b c d e f
22
Hex to Binary
Convention write 0x before number Hex to Binary just convert digits
Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f
0x2ac
0010 1010 1100
0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
0x2ac = 001010101100
23
Binary to Hex
Just convert groups of 4 bits
Bin 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f
101001101111011 = 0x537b
24
Dec
Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f
Hex to Decimal
Just multiply each hex digit by decimal value, and
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0x2ac 2 256
163 4096
+ 10 16 + 12 1 = 684
162 256 161 16 160 1
25
Decimal to Hex
1. 2. 3. 4.
Analogous to decimal binary. Find largest power-of-16 smaller than decimal number Divide by power-of-16. The integer result is hex digit. The remainder is new decimal number. Do the same thing again
26
Dec
Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f
Decimal to Hex
684 684/256 = 2 684%256 = 172 172/16 = 10 = a
163 4096 162 256 161 16
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0x2__
27
Octal
Octal is base 8 Similar to hexadecimal Conversions Less convenient for use with 8-bit bytes
28
Arithmetic -- addition
Binary similar to decimal arithmetic
No carries
1 0 0 0 0 1 1
0 1
1 0 0 1
1 1 1 1
0 1 1 0
0 0 1 1
Carries
0 + 1 1
1 0 1
1 0 1
+ 1 1 0
29
Arithmetic -- subtraction
No borrows
0 1 1 0 0 0 0 1 1 0
0 1 0 1
1 1 0 0
1 1 1 1
0 0 1 1
Borrows
1 1 0
0 0 0
1 0 1
0 - 1 results in a borrow
30
Arithmetic -- multiplication
1 X 1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 1 1 1 0 1 0 1 1 1
Successive additions of multiplicand or zero, multiplied by 2 (102). Note that multiplication by 102 just shifts bits left.
31
Hexadecimal Arithmetic
Similar If youre doing by hand, easiest to convert each set of
Instead of storing the - sign with the number computer simply assign one bit as a sign bit Then how computer performs arithmetic?
0000 0101 0000 0100 0000 0011 0000 0010 0000 0001 0000 0000 1111 1111 1111 1110 1111 1101 1111 1100 1111 1011
Complements of numbers
(r-1 )s Complement
Given a number N in base r having n digits, complement of N is defined as (rn - 1) - N For decimal numbers the base or r = 10 and r- 1= 9, so the 9s complement of N is (10n-1)-N 99999. - N the (r- 1)s
9 Digit n-1
9 Next digit
9 Next digit
9 First digit
Digit n
9s complement Examples
9 9 4 5 9 6 3 9 7 2 9 0 9 9 0 9
Example: Find the 9s complement of 546700 and 12389 The 9s complement of 546700 is 999999 - 546700= 453299
5 4
9 2 7
9 3 6
9 8 1
9 9 0
1 8
1s complement
For binary numbers, r = 2 and r 1 = 1, r-1s complement is the ls complement. The ls complement of N is (2n - 1) - N.
Bit n-1
Bit n-2
Bit 1
Bit 0
1 Digit n-1
1 Next digit
1 Next digit
1 First digit
Digit n
ls complement
Find r-1 complement for binary number N with four binary digits. r-1 complement for binary means 2-1 complement or 1s complement. n = 4, we have 24 = (10000)2 and 24 - 1 = (1111)2. The ls complement of N is (24 - 1) - N. = (1111) - N
ls complement
1 0 1
1 1 0
1 1 0
1 0 1
1 0 1
1 1 0
1 0
1 0 1
1 0 1
1 1 0
1 1 0
1 1 0
1 1 0
0 1
rs Complement
Given a number N in base r having n digits, the rs complement of N is defined as rn - N. For decimal numbers the base or r = 10,
1 0 0 Digit n-1 0 Next digit 0 Next digit 0 First digit
Digit n
0 5 4
0 4 5
0 6 3
0 7 3
0 0 0
0 0 0
0 1 8
0 2 7
0 3 6
0 8 1
0 9 1
2s complement
For binary numbers, r = 2, rs complement is the 2s complement. The 2s complement of N is 2n - N.
0 Digit n-1
0 Next digit
0 Next digit
0 First digit
Digit n
2s complement Example
1 0 1 0 0 0 1 0 1 0 0 1 0 0 0 1 0 0 1 0 1 1
0 0 1
0 0 1
0 0 1
0 1 0
0 1 0
0 1 0
0 1 1
Method 1:
The 2s complement of binary number is obtained by adding 1 to the ls complement value. Example: 1s complement of 101100 is 010011 (invert the 0s and 1s) 2s complement of 101100 is 010011 + 1 = 010100
Examples
Finding the 2s complement of (01100101)2 Method 1 Simply complement each bit and then add 1 to the result. (01100101)2 [N] = 2s complement = 1s complement (10011010)2 +1 =(10011011)2 Method 2 Starting with the least significant bit, copy all the bits up to and including the first 1 bit and then complement the remaining bits. N =01100101 [N] = 1 0 0 1 1 0 1 1
MN N (rn N )
Sum = M + ( r n N)
sum. (2) if M < N, take the rs complement of sum and place negative sign in front of sum. The answer is negative.
Example 1 (Decimal unsigned numbers), perform the subtraction 72532 - 13250 = 59282. M > N : Case 1 Do not take complement of sum and discard carry The 10s complement of 13250 is 86750. Therefore: M= 72532 10s complement of N =+86750 Sum= 159282 Discard end carry 105= - 100000 Answer = 59282 no complement
Example 2; Now consider an example with M <N. The subtraction 13250 - 72532 produces negative 59282. Using the procedure with complements, we have M = 13250 10s complement of N = +27468 Sum = 40718 Take 10s complement of Sum = 100000 -40718 The number is : 59282