0% found this document useful (0 votes)
14 views20 pages

Week 6 Lecture 11 (Delivered)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views20 pages

Week 6 Lecture 11 (Delivered)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

CSE101 Intro to CS and Programming

Boolean Algebra and Logic Circuits


Lecture 10 (Week 6)
By Mr. Faheem Shaukat
[email protected]
CCoommppuutterer FFununddaammenenttaallss:: PPrradadeeeepp

KK.. SSiinhnhaa &&PPrriititi SSiin


anha
h
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Learning
Objectives
In this chapter you will learn about:

 Reasons for using binary instead of


decimal numbers
 Basic arithmetic operations using binary numbers
 Addition (+)
 Subtraction (-)
 Multiplication (*) (Out of Course)
 Division (/) (Out of Course)

Ref Page 49 Chapter 5: Computer Arithmetic Slide 3/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Binary over Decimal

 Information is handled in a computer by


electronic/ electrical components
 Electronic operate in binary mode (can
components
only indicate two states – on (1) or off (0)
 Binary number system has only two digits (0 and
1), and is suitable for expressing two possible states
 In binary system, computer circuits only have to handle
two binary digits rather than ten decimal digits causing:
 Simpler internal circuit design
 Less expensive
 More reliable circuits
 Arithmetic rules/processes with binary
possible numbers

Ref Page 49 Chapter 5: Computer Arithmetic Slide 4/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Examples of a Few Devices that work in


Binary Mode

Binary On (1) Off (0)

State

Bulb

Switch

Circuit
Pulse

Ref Page 50 Chapter 5: Computer Arithmetic Slide 5/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Binary Arithmetic

 Binary arithmetic is simple to learn as binary number


system has only two digits – 0 and 1

 Following slides show rules and example for the


four basic arithmetic operations using binary numbers

Ref Page 50 Chapter 5: Computer Arithmetic Slide 6/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Binary Addition

Rule for binary addition is as follows:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0 plus a carry of 1 to next higher column

Ref Page 50 Chapter 5: Computer Arithmetic Slide 7/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Binary Addition (Example 1)


Example
Add binary numbers 10011 and 1001 in both decimal
and binary form

Solution

Binary Decimal

carry 11 carry 1
10011 19
+1001 +9

11100 28

In this example, carry are generated for first and second columns

Ref Page 51 Chapter 5: Computer Arithmetic Slide 8/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Binary Addition (Example 2)

Example

Add binary numbers 100111 and 11011 in both decimal


and binary form

Solution
The addition of three 1s
Binary Decimal can be broken up into two
steps. First, we add only
carry 11111 carr 1 two 1s giving 10 (1 + 1 =
y 10). The third 1 is now
added to this result to
100111 39
obtain 11 (a 1 sum with a 1
+11011 +27 carry). Hence, 1 + 1 + 1 =
1000010 66 1, plus a carry of 1 to next
higher column.

Ref Page 51 Chapter 5: Computer Arithmetic Slide 9/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Binary Subtraction

Rule for binary subtraction is as follows:

0 - 0 = 0
0 - 1 = 1 with a borrow from the next column
1 - 0 = 1
1 - 1 = 0

Ref Page 51 Chapter 5: Computer Arithmetic Slide 10


/29
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Binary Subtraction (Example)

Example

Subtract 011102 from 101012

Solution

12
0202
10101
-01110

00111

Note: Go through explanation given in


the book

Ref Page 52 Chapter 5: Computer Arithmetic Slide 11/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Complement of a Number

Number of digits
in the number

C = Bn
- 1 - N

Complement Base of the The number


of the number number

Ref Page 52 Chapter 5: Computer Arithmetic Slide 12/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Complement of a Number (Example 1)

Example

Find the complement of 3710

Solution

Since the number has 2 digits and the value of


base is 10,
(Base)n - 1 = 102 - 1 = 99
Now 99 - 37 = 62

Hence, complement of 3710 = 6210

Ref Page 53 Chapter 5: Computer Arithmetic Slide 13/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Complement of a Number (Example 2)

Example
Find the complement of 68

Solution
Since number has 1 digit and the value
of
the base
(Base)n - 1 = 81 - 1 = 710 = 78
is 8, Now 78 - 68 = 18

Hence, complement of 68 = 18

Ref Page 53 Chapter 5: Computer Arithmetic Slide 14/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Complement of a Binary
Number
Complement of a binary number can be obtained
by transforming all its 0’s to 1’s and all its 1’s to 0’s

Example
Complement of 1 0 1 1 0 1 0 is

1
Ref Page 53 Chapter 5: Computer Arithmetic Slide 15/29

0
Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Complementary Method of
Subtraction
Involves following 3 steps:

Step 1: Find the the number


complement of are you
subtracting (subtrahend)
from which
Step 2: Add this to you
the number are
taking away (minuend) add it to
the result; if there is no carry, recomplement
obtain the
Step sumthere
3: If and attach
is a acarry
negative
of sign
1,

Complementary subtraction is an additive approach of subtraction

Ref Page 53 Chapter 5: Computer Arithmetic Slide 16/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Complementary Subtraction (Example 1)

Example:
Subtract 5610 from 9210 using complementary method.

Solution
Step 1: Complement of 5610
= 102 - 1 - 56 = 99 – 56 The result may be
= 4310 verified using the
method of
Step 2: 92 + 43 (complement of 56) normal
= 135 (note 1 as carry) subtraction:
Step 3: 35 + 1 (add 1 carry to sum) 92 - 56 = 36

Result = 36

Ref Page 53 Chapter 5: Computer Arithmetic Slide 17/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Complementary Subtraction (Example 2)

Example
Subtract 3510 from 1810 using complementary method.

Solution

Step 1: Complement of 3510 Step 3: Since there is no carry,


= 102 - 1 - 35 re-complement the sum and
= 99 - 35 attach a negative sign to
= 6410 obtain the result.

Result = -(99 - 82)


Step 2: 18 = -17
+ 64 (complement
of 35) The result may be verified using normal
82 subtraction:

18 - 35 = -17

Ref Page 53 Chapter 5: Computer Arithmetic Slide 18/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Binary Subtraction Using Complementary
Method (Example 1)

Example
Subtract 01110002 (5610) from 10111002 (9210) using
complementary method.

Solution
1011100
+1000111 (complement of 0111000)

10100011

1 (add the carry of 1)

0100100

Result = 01001002 = 3610

Ref Page 53 Chapter 5: Computer Arithmetic Slide 19/29


Computer Fundamentals: Pradeep K. Sinha & Priti Sinha
Binary Subtraction Using Complementary
Method (Example 2)

Example
Subtract 1000112 (3510) from 0100102 (1810) using
complementary method.

Solution
010010
+011100 (complement of 100011)

101110

Since there is no carry, we have to complement the sum and


attach a negative sign to it. Hence,

Result = -0100012 (complement of 1011102)


= -1710

Ref Page 54 Chapter 5: Computer Arithmetic Slide 20/29

You might also like