26/9/2020
Tutorial 1: Digital Systems & Binary
Numbers, Boolean Algebra, and
Logic Gates
ENGG 2020
Outline
• Number Systems
– Binary, Octal, Hexadecimal Numbers
– 1’s complement and 2’s complement
– Addition and subtraction
• Boolean Algebra
– Logic Gates
– Boolean Theorems
– De Morgan’s Theorem
1
26/9/2020
Transformation of Number System
Positional number systems
D d 2 r 2 d1 r 1 d 0 r 0 d 1 r 1 d 2 r 2
D Number d digit r base/radix
Number: a string of digits;
Each digit position has a different weight;
2
26/9/2020
Positional number systems
Any Decimal Number D Can Be Represented as the
Following:
D = dp-1 dp-2 ... d1 d0 . d-1 d-2 ... d-n
p 1
d
i n
i ri Extending to:
D2 = ∑ d i × 2i
Weight of digit in position i ; D16= ∑ d i × 16i
the radix may be any integer r≥2
Use a subscript to indicate the radix of each number 5
Examples of positional number system
Decimal system:
base is 10, the digit may be 0 to 9
101.110 1102 0 101 1100 1101
Binary system:
base is 2, the digit may be 0 or 1
101.012 1 2 2 0 21 1 20 0 2 1 1 2 2
6
3
26/9/2020
Example 1
• Convert (10100)2 to base-10
• Convert (274)8 to base-10
Answer 1
4
26/9/2020
Example 2
• Convert (1101.011)2 to base-8
• Convert (AF3.15)16 to base-10
Answer 2
10
5
26/9/2020
Answer 2
11
Example 3
• Convert (234)10 to base-8
• Convert (234)10 to base-16
• Convert (0.25)10 to base-2
12
6
26/9/2020
Answer 3
13
Answer 3
14
7
26/9/2020
Answer 3
• Convert (0.25)10 to base-2
Hence, (0.25)10 = (0.01)2
15
Take Home Exercise 1
• Convert (0.1285)10 to base-8
• Convert (0.828125)10 to base-2
16
8
26/9/2020
Take Home Exercise 2
• Convert (18.6)9 to base-11
17
Take Home Exercise 3
• Convert (1011011.1010111)2 to base-8
• Convert (AF.16C)16 to base-8
18
9
26/9/2020
2’s Complement and 1’s Complement
• Method of complements is a technique used
to subtract one number from another using
only addition
– Subtraction:
A – B = A + (-B) = A + Complement of B
19
2’s Complement and 1’s Complement
• 1’s Complement
– Convert all 0s to 1s and all 1s to 0s
• 2’s Complement
– Method 1: n bits, -A = 2(n-1) – A
– Method 2: -A = 1’s complement of A + 1
For 8 bits,
27 = 1000 0000
20
10
26/9/2020
Number Ranges Represented by
1’s & 2’s Complements
Unsigned Unsigned Signed 1’s Signed Signed 2’s Signed
Binary Decimal Complement Decimal Complement Decimal
000 0 111 -0 000 0
001 1 110 -1 111 -1
010 2 101 -2 110 -2
011 3 100 -3 101 -3
100 4 011 +3 100 -4
101 5 010 +2 011 +3
110 6 001 +1 010 +2
111 7 000 +0 001 +1
• Ranges of different n bits binary representations:
• Unsigned number, from 0 to +(2n-1)
• Signed 1’s complement, from –(2(n-1)-1) to +(2(n-1)-1), with 2 zeros
• Signed 2’s complement, from –(2(n-1)) to +(2(n-1)-1)
21
Addition and Subtraction
• Addition
– 1’s Complement: add carry bit to the result
– 2’s Complement: discard carry bit
• Subtraction
– 1’s Complement: A – B = A + 1’s Complement of B
– 2’s Complement: A – B = A + 2’s Complement of B
22
11
26/9/2020
1’s Complement
• Addition
– 1’s Complement: add carry bit to the result
• Subtraction
– Take 1’s complement of the subtrahend
– Add with the minuend
– If the result of the above addition has carry bit, then
add it to the LSB
– If there is no carry bit 1, then take 1’s complement of
the result which will be negative
23
Overflow
• If the result of a n-bit arithmetic operation is too large
to fit into the resultant n-bit, then arithmetic overflow
occurs.
• Therefore:
– Adding two positive numbers must give a positive result
– Adding two negative numbers must give a negative result
– Overflow (when correct representation of the result
requires more than n bits)
– Sum of two positive numbers yields a negative result or
sum of two negative numbers yields a positive result
– The carry out of the sign position is not equal to the carry
into the sign position
24
12
26/9/2020
• Exercise 1:
Assuming that the computer uses 4-bit 2’s
complement arithmetic, show how it would
compute
3+4, 5+6, 5+(-6), (-5)+6, (-3)+(-4), (-5)+(-6)
and show whether there is an overflow
25
+5
26
13
26/9/2020
-5
27
• Exercise 2:
Assuming that the computer uses 4-bit 1’s
complement arithmetic, show how it would
compute
3+4, 5+6, 5+(-6), (-5)+6, (-3)+(-4), (-5)+(-6)
and show whether there is an overflow
28
14
26/9/2020
29
• Take Home Exercise 4 :
A and B are integer variables in a computer
program, with 𝐴 = (25) and B = −(46) .
Assuming that the computer uses 8-bit 2’s
complement arithmetic, show how it would
compute
A+B, A-B, B-A, -A-B
30
15
26/9/2020
Binary Codes
• ASCII (American Standard Code for
Information Interchange)
– Uses 7 bits to represent 94 graphics printing
characters and 34 control characters
– Extended ASCII (8 bits) include more graphic
characters
31
Parity Bit
• An extra bit is added to make the sum of ‘1’s
even or odd.
• Parity can be used to detect odd number of
bits in error, but cannot correct any error
32
16
26/9/2020
• Take Home Exercise 5 :
Encode the message CATCH 22 in ASCII code
with even parity and group the coded word into
16-bit segments
Hint:
There is a
blank in
between
‘H’ and ‘2’
33
Logic Gates
• AND gate: output is 1 only when all inputs are
1’s
• OR gate: output is 0 only when all inputs are
0’s
• XOR gate: output is 1 only when two inputs
are different
• NOT gate, NOR gate, NAND gate …
34
17
26/9/2020
Boolean Theorems
• Elements : true or false ( 1, 0)
• Operations: a OR b; a AND b, NOT a
e.g.
0 OR 1 = 1 0 OR 0 = 0
1 AND 1 = 1 1 AND 0 = 0
NOT 0 = 1 NOT 1 = 0
35
Boolean Theorems
(A1) X = 0 if X 1 (A1’) X = 1 if X 0
(A2) If X = 0, then X’ = 1 (A2’) if X = 1, then, X’ = 0
(A3) 0·0 = 0 (A3’) 1 + 1 = 1
(A4) 1·1 =1 (A4’) 0 + 0 = 0
(A5) 0·1=1·0=0 (A5’) 1 + 0 = 0 + 1 = 1
(T1) X + 0 = X (T1’) X · 1 = X (Identities)
(T2) X + 1 = 1 (T2’) X · 0 = 0 (Null elements)
(T3) X + X = X (T3’) X · X = X (Idempotency)
(T4) (X’)’ = X (Involution)
(T5) X + X’ = 1 (T5’) X · X’ = 0 (Complements)
(T6) X + Y = Y + X (T6’) X · Y = Y · X (Commutativity)
(T7) (X + Y) + Z = X + (Y + Z) (T7’) (X · Y) · Z = X · (Y · Z) (Associativity)
(T8) X · Y + X · Z = X · (Y + Z) (T8’) (X + Y) · (X + Z) = X + Y·Z (Distributivity)
(T9) X + X · Y = X (T9’) X · (X + Y) = X (Covering)
(T10) X · Y + X · Y’ = X (T10’) (X + Y) · (X + Y’) = X (Combining)
(T11) X · Y + X’· Z + Y · Z = X · Y + X’ · Z (Consensus)
(T11’) (X + Y) · ( X’ + Z) · (Y + Z) = (X + Y) · (X’ + Z)
(T12) X + X + . . . + X = X (T12’) X · X · . . . · X = X (Generalized idempotency)
(T13) (X1 ·X2· . . . . Xn)’ = X1’ + X2’ + . . . + Xn’
(T13’) (X1 + X2 + . . . + Xn)’ = X1’ · X2’ · . . .·Xn’ (DeMorgan’s theorems)
36
18
26/9/2020
Boolean Theorems
37
38
19
26/9/2020
39
40
20
26/9/2020
41
Example 1
Why
x + x’y = x + y ?
Answer: x + x’y = x(1+y) + xy’
= x + xy + x’y
= x + (x+x’)y
=x+y
42
21
26/9/2020
Take Home Exercise 6
Simplify: (A + C)(AD + AD’) + AC + C
43
Take Home Exercise 7
TRUE OR FALSE?
44
22
26/9/2020
45
45
23