Department of Computer Science and Engineering, BRAC University
Lecture 1
Number System & Calculations
CSE260 : Digital Logic Design
Objective Analog vs. Digital
➔ Distinguish between ➔ Analog data can vary over
analog and digital a continuous range of
system values.
➔ Understand the Example: speedometer
advantage and limitation ➔ Digital quantities can take
of digital system on only discrete values (0
➔ Understand the meaning and 1, high and low).
of digital logic Example: Digital
Computer, Decimal Digits,
Alphabets
2
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Digital System
• A digital system is a combination of devices
designed to manipulate physical quantities or
information that are represented in digital form.
• “A discreet information processing system”
• Signals: Discreet information
3
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Digital System Advantages Limitation
➔ Greater accuracy or ➔ The real world is mainly
precision analog
➔ Easier to design (generality)
➔ Easier information storage
➔ Programmability
(instructions)
➔ Speed
➔ Economical
4
Department of Computer Science and Engineering CSE260 - Digital Logic Design
How to Overcome the Limitations
• Convert the real world analog input data into digital
• Process this digital data
• Then again convert into analog form
Processing
Analog A. to D. Digital D. to A. Analog
Input Conversion Data Conversion Output
5
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Digital Logic
• Design logic is a term used to denote the design and
analysis of digital system
• Digital logic is concerned with the interconnection
among digital components and modules
• Digital logic design is engineering and engineering
means problem solving
6
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Number systems and codes
● Digital Systems are built from circuits that process
binary digits. BUT very few real-life problems are
based on binary numbers
● So, a digital system designer must establish some
correspondence between the binary digits
processed by digital circuits and real-life numbers,
events and conditions
7
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Information representation
• Human decisions tends to be binary i.e. Yes or No
• Elementary storage units inside computer are electronic
switches. Each switch holds one of two states: on (1) or off (0).
ON OFF
(1) (0)
8
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Information representation [cont.]
● We use a bit (binary digit), 0 or 1, to represent the state
● Storage units can be grouped together to cater for larger
range of numbers. Example: 2 switches to represent 4 values
0 (00)
1 (01)
2 (10)
3 (11)
9
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Information representation [cont.]
▪ In general, N bits can represent 2N different values.
1 bit → represents up to 2 values (0 or 1)
2 bits → rep. up to 4 values (00, 01, 10 or 11)
3 bits → rep. up to 8 values (000, 001, 010. …, 110, 111)
4 bits → rep. up to 16 values (0000, 0001, 0010, …, 1111)
▪ For M values, bits are needed.
32 values → requires 5 bits
64 values → requires 6 bits
1024 values → requires 10 bits
40 values → requires 6 bits
100 values → requires 7 bits
10
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Positional Notations
• Decimal number system, symbols = { 0, 1, 2, 3, …, 9 }
• Position is important
Example:
(7594)10 = (7x103) + (5x102) + (9x101) + (4x100)
• In general,
(anan-1… a0)10 = (an x 10n) + (an-1 x 10n-1) + … + (a0 x 100)
(2.75)10 = (2 x 100) + (7 x 10-1) + (5 x 10-2)
• In general,
• (anan-1… a0 . f1f2 … fm)10 = (an x 10n) + (an-1x10n-1) + … + (a0 x 100) +
(f1 x 10-1) + (f2 x 10-2) + … + (fm x 10-m)
11
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Other Number Systems
▪ Binary (base 2): weights in powers-of-2. Binary digits
(bits): 0,1
▪ Octal (base 8): weights in powers-of-8. Octal digits:
0,1,2,3,4,5,6,7
▪ Hexadecimal (base 16): weights in powers-of-16.
Hexadecimal digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Note: when base is r, coefficient values range from 0 to
r-1.
12
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Other Number
Binary Octal Decimal Hexadecimal
0000 0 0 0
Systems [cont] 0001
0010
1
2
1
2
1
2
0011 3 3 3
▪ Binary (base 2): weights 0100 4 4 4
in powers-of-2. Binary 0101 5 5 5
digits (bits): 0,1 0110 6 6 6
0111 7 7 7
▪ Octal (base 8): weights
1000 10 8 8
in powers-of-8. Octal
1001 11 9 9
digits: 0,1,2,3,4,5,6,7
1010 12 10 A
▪ Hexadecimal (base 16): 1011 13 11 B
weights in powers-of-16. 1100 14 12 C
Hexadecimal digits: 1101 15 13 D
0,1,2,3,4,5,6,7,8,9,A,B,C, 1110 16 14 E
D,E,F 1111 17 15 F
13
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Base-R to Decimal Conversion
***Formula= ∑ digit * source_base position (2A.8)16
(1101.101)2 = 2×161 + 10×160 + 8×16-1
= 1×23 + 1×22 + 1×20 + 1×2-1 + 1×2-3
= 32 + 10 + 0.5
= 8 + 4 + 1 + 0.5 + 0.125
= (13.625)10 = (42.5)10
(572.6)8 (341.24)5
= 5×82 + 7×81 + 2×80 + 6×8-1 = 3×52 + 4×51 + 1×50 + 2×5-1 +
4×5-2
= 320 + 56 + 2 + 0.75
= 75 + 20 + 1 + 0.4 + 0.16
= (378.75)10
= (96.56)10 14
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Decimal to Base-R Conversion
❖ Whole numbers: repeated division-by-R
❖ Fractions: repeated multiplication-by-R
15
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Repeated Division-by-2 Method
▪ To convert a whole number to
binary, use successive division
by 2 until the quotient is 0. The
remainders form the answer,
with the first remainder as the
least significant bit (LSB) and
the last as the most significant
bit (MSB).
(43)10 = (101011)2
16
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Repeated Multiplication-by-2 Method
▪ To convert decimal fractions to
binary, repeated multiplication
by 2 is used, until the fractional
product is 0 (or until the desired
number of decimal places). The
carried digits, or carries,
produce the answer, with the
first carry as the MSB, and the
last as the LSB.
(0.3125)10 = (.0101)2
17
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Repeated Multiplication-by-2 Method
Integer Fraction
➔ Division by base of ➔ Multiplication by base of
target no. system target no. system
➔ Remainders are ➔ Integers are
accumulated accumulated
➔ By division we obtain ➔ By multiplication we
LSB to MSB obtain MSB to LSB
18
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Binary-Octal/Hexadecimal Conversion
▪ Binary → Octal: Partition in groups of 3
(10 111 011 001 . 101 110)2 = (2731.56)8
▪ Octal → Binary: reverse
(2731.56)8 = (10 111 011 001 . 101 110)2
▪ Binary → Hexadecimal: Partition in groups of 4
(101 1101 1001 . 1011 1000)2 = (5D9.B8)16
▪ Hexadecimal → Binary: reverse
(5D9.B8)16 = (101 1101 1001 . 1011 1000)2
19
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(1) Try converting this to
(10110001101011.111100000110)2
a) octal
b) hexadecimal
(2) Try converting these to binary
a) (673.124)8
b) (306.D)16
20
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise Answers
1. a) (26153.7406)8
b) (2C6B.F06)16
2. a) (110 111 011 . 001 010 100)2
b) (0011 0000 0110 . 1101)2
21
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Binary Addition: Addition Rules w/Carries
For 2 bit For 3 bit
➔ 0+0=00 ➔ 0+0+0 = 0 0
◆ ( 0 with a 0 carry ) ◆ (0 with 0 carry)
➔ 0+1=01 ➔ 0+0+1 = 0 1
◆ ( 1 with a 0 carry ) ◆ (1 with 0 carry)
➔ 1+0=01 ➔ 0+1+1 = 1 0
◆ ( 1 with a 0 carry ) ◆ (0 with 1 carry)
➔ 1+1=10 ➔ 1+1+1 = 1 1
◆ ( 0 with a 1 carry ) ◆ (1 with 1 carry)
22
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Adding Binary Numbers
0 1 1 1 0 0 0
28 ⎯→ 00011100
+ 43 ⎯→ + 00101011
71 01000111
23
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(3) Add (101101)2 with (100111)2
24
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise Solution
(3) (1010100)2
Working:
Augend: 101101
Addend: +100111
Sum: 1010100
25
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Addition of base-r
Example: 4+1+4= 9
(34)5+(41)5+ (24)5 9%5=4 (sum)
9/5=1 (carry)
21
( 3 4 )5 1+3+4+2= 10
( 4 1 )5 10%5=0 (sum)
+ ( 2 4 )5 10/5=2 (carry)
________________
(2 0 4)5 (Ans)
26
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(4) (a) (FF)16+(F1)16
(b) (66)7 + (55)7
Solution
(a) (1F0) 16
(b) (154) 7
27
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Binary Multiplication
• The multiplication of two binary numbers can be carried
out in the same manner as the decimal multiplication.
• Unlike decimal multiplication, only two values are
generated as the outcome of multiplying the
multiplication bit by 0 or 1 in the binary multiplication.
These values are either 0 or 1.
• The binary multiplication can also be considered as
repeated binary addition. Therefore, the binary
multiplication is performed in conjunction with the binary
addition operation.
28
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(5) Multiply 1011 with 101
Multiplicand 1011
Multiplier x 101
Partial Product 1011
0000X
1011XX
Product 110111
29
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Multiplication with base-r
2A3C 7*C = 7*12 = 84 =(write 4, carry 5)
7*3+5 = 26 = 1A (write A, carry 1)
xB7 7*A+1 = 71 = 0x47 (write 7, carry 4)
7*2+4 = 18 = 0x12
127A4 This completes the 7*2A3C = 127A4 partial product.
1D094X B*C = 11*12 = 132 = (write 4, carry 8)
B*3+8 = 11*3+8 = 41 = (write 9, carry 2)
1E30E4 B*A+2 = 11*10+2 = 112 = (write 0, carry 7)
B*2+7 = 11*2+7 = 29 = 1D
This completes the B[0]*2A3C = 1D094[0] partial product, where I'm noting the [0]
digits to remind us this is in the 16s column.
Working Adding the partial products: 127A4 + 1D0940
4+0 = 4
A+4 = E
7+9 = 16 = 0x10 (write 0, carry 1)
2+0+1 = 3
1+D = E
1=1
30
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(6) (a) Multiply (34)5 with (42)5
(b) Multiply (25)9 with (36)9
Solution
(a) (3133)5
(b) (1033)9
31
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Binary Subtraction: Rules w/Carries
For 2 bit
• 0 - 0 = 0 0 ( 0 with a 0 carry )
• 1 - 1 = 0 0 ( 0 with a 0 carry )
• 1 - 0 = 0 1 ( 1 with a 0 carry )
• 0 - 1 = ? ( ???)
32
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Binary Subtraction: Rules w/Carries
0 2
2 → 10
- 1 → - 01
1 → 01
4 → 100
- 1 → - 001
3 → 011
33
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(7) (b) Subtract (100111)2 from (101101)2
Solution
(000110) 2
Working
Minuend: 101101
Subtrahend: −100111
Difference: 000110
34
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Binary Subtraction: Rules w/Carries
3 16
4 6
(4 A 6)16 (5 4)6
-(1 B 3)16 -(3 5)6
(2 F 3)16 (1 5)6
35
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(8) (a) (71)8-(56)8 (b) (21)3-(12)3
Solution
a) (13)8
b) (2)3
36
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Division of base-r Iteration 1 Iteration 2
Dividend: x1x2x3...xm; Divisor: y1y2...yn = y;
10│ 101 │0 10│ 101 │01
Perform 1012 / 102; Dividend = 101 and Divisor = 10
│ 0 │ │ 0 │
10 10
Step1: Start with the first digit of the dividend. (x1)
-10 _
Step2: Compare it with the divisor;
0
If (it is smaller, than the divisor): (x1<y)
2.a append 0 to the quotient. Iteration 3
else: (x1 >= y) 10│ 101 │010
proceed with division.
│ 0 │
2.a Find the largest multiple of the divisor that fits.
10
2.b Append the multiplier to the quotient.
-10 _
Step3: Subtract and bring down the next digit.
01
Step4: From now on compare the newly formed number - 0 _
in step3 with the divisor while repeating step2. 1
Step5. Repeat this step 2, 3 & 4 until all digits of the dividend
(x1x2x3...xm) are processed.
37
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(9) Perform
10111012 / 1102;
Find the quotient
and remainder Alt. Solution
Solution
38
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(10) Perform
2341025 / 3215;
Find the quotient
and remainder.
Solution
39
Department of Computer Science and Engineering CSE260 - Digital Logic Design
Exercise
(11) (a) (71)8/ (56)8 (b) (21)3/ (12)3
Find the quotient and remainder.
Solution
Do it yourself & Compare the answer with your peers.
40
Department of Computer Science and Engineering CSE260 - Digital Logic Design