d75p 34r - hnc computer architecture week 8 more boolean logic © c nyssen/aberdeen college 2004 all...

23
D75P 34R - HNC Computer Architecture Week 8 More Boolean Logic C Nyssen/Aberdeen College 2004 l images © Focus Clipart, used with permission except cecar, burglar, wedding © Microsoft epared 24/11/04

Upload: nelson-briggs

Post on 04-Jan-2016

216 views

Category:

Documents


3 download

TRANSCRIPT

D75P 34R - HNC Computer Architecture

Week 8

More Boolean Logic

© C Nyssen/Aberdeen College 2004All images © Focus Clipart, used with permission exceptRacecar, burglar, wedding © MicrosoftPrepared 24/11/04

We looked already at Boolean Logic, which is of great importance to how computers manipulate data.

Boolean logic is essentially very simple. You may have already used Boolean Search Expressions when using Internet Search Engines.

When used in constructing a search expression, it can be very useful in specifying exactly what information you want.

When using AND in this search expression, results retrieved will contain both dog and cat information. The results will not include those documents containing only dog or cat information. In the diagram the documents retrieved by using this search expression are contained within the green area.

Boolean 'AND' This is expressed as ‘dogs AND cats' in a search.

A scientist wishes to test the old adage “fighting like cat and dog”. To do this, he needs to find some people to interview who keep both cats and dogs.

People who don’t have a pet at all, or have only a cat or only a dog, are useless for the purposes of his experiments.

We can show the logic in a diagram like this…

Cat owner?

Dog owner?

Possible experimental subject?

  Cat?   Dog? Suitable subject?

0 0 0

0 1 0

1 0 0

1 1 1

Remember the Truth Table for an AND gate works like this…

Such a search will not merely retrieve documents containing only dog information or only cat information. In the diagram the documents retrieved by using this search expression are contained within all the coloured areas.

Boolean ‘OR'

This is expressed as ‘dogs OR cats' in a search. All the results retrieved will contain either dog information, or cat information, or dog-and-cat information together.

An insurance company have introduced a new policy for Pet Owners. They have purchased a mailing list with information about peoples households; now they want to send a mail shot to potential customers.

The insurance company needs to target those people who have a cat, or a dog, or both, but there is no point sending a mailshot to people who don’t keep a pet at all.

We can show the logic in a diagram like this…

Cat owner?

Dog owner?

Try and sell a policy?

  Cat?   Dog? Hard Sell?

0 0 0

0 1 1

1 0 1

1 1 1

Remember the Truth Table for an OR gate works like this…

When using NOT in this search expression, results will contain only dogs. The NOT operator will exclude cats completely and thus any dog-and-cat information will be excluded also. In this diagram the dog related information is contained within the blue area.

Boolean ‘NOT’                                                                    This is expressed as ‘dogs NOT cats' in a search.

Pat is a Postman delivering mail to peoples houses...

...but unfortunately he just does not get along with dogs!

So he only visits homes that have no dogs in residence…

We can show the logic in a diagram like this…

Dog in residence? Deliver mail?

Dog present?  

Deliver mail?

0 1

1 0

Remember the Truth Table for a NOT gate works like this…

Boolean ‘XOR’                                                                    This is expressed as ‘dogs XOR cats' in a search. It must include one, or the other, but not both, and not none!

A Vet’s surgery have to send out annual reminders for all cats and dogs to come in for their booster shots.

They need to go through all their patient’s files and send out letters to all the dog owners and all the cat owners…

…but not the owners of canaries, goldfish or hamsters….

… and owners with dogs AND cats would already have been counted!

We can show the logic in a diagram like this…

Cat owner?

Send reminder?

Remember the Truth Table for an XOR gate works like this…

Dog owner?

01 1

10 1

11 0

00 0

Reminder? Dog?   Cat?  

Try to draw the Logic Circuit for the following scenario.

To ride the go-karts at the fairground, you have to be 16 or over, OR be 12 or over AND accompanied by a responsible adult.

12-15?

Adult present?

=> 16?

Allowed on the go-karts?

12-15?

Adult present?

=> 16?

Allowed on the go-karts?

12-15? With adult?

=>16? Ride karts?

0 0 0 1 0 0 1 1 0 1 1 1 0 1 1 0 0 1

Complete the Truth Table.

A burglar alarm will go off if it has been set, AND the door is opened without the correct code number, OR someone breaks the infra-red beam by climbing in the window.

Break beam?

Open door without code?

Alarm set?

Alarm goes off?

Break beam?

Open door without code?

Alarm set?

Alarm goes off?

Breakbeam?

Opendoor?

Alarmset?

Alarm,goes off?

0 0 01 0 01 1 01 1 10 1 10 0 1

Complete the Truth Table.

To be legally married in Scotland, both parties must be 16 or over, not already married, and of different sexes.

Person #2 married?

Person #1 married?

Person #2 => 16?

Person #1 => 16?

Person #1 is a man?

Person #2 is a man?

Marriage is legal?

There are many different ways to depict the circuit for this scenario. This is just one of them!

Person 1 man?

Person 2 man?

Person 1 =>16?

Person 2 =>16?

Person 1 married?

Person 2 Married?

Outcome?

1 0 1 1 1 0

1 0 1 0 0 0

1 1 1 1 0 0

0 1 1 1 0 0

1 0 1 0 1 0

Complete the Truth Table.

Your exam question will typically consist of a pair of binary numbers, and you will be asked to perform logical operations with them.

1010 0000 1111 0101

1111 1111 0000 0000

AND

OR

XOR

NAND

NOR

XNOR

1111 1111 1111 0101

0101 1111 1111 0101

0101 1111 1111 11110000 0000 0000 1010

1010 0000 0000 1010

1010 0000 0000 0000

Another one?

1100 0011 0101 1101

1001 1001 0000 0010

AND

OR

XOR

NAND

NOR

XNOR

1101 1011 0101 1111

0101 1010 0101 1111

0111 1110 1111 11110010 0100 1010 0000

1010 0101 1010 0000

1000 0001 0000 0000

Summary

NOT (inverter) reverses any input. AND requires ALL inputs to be TRUE for a TRUE output. OR requires only ONE input to be TRUE for a TRUE output. XOR requires differences in the inputs for a TRUE output. NAND is equivalent to an AND immediately followed by a NOT. NOR is equivalent to an OR immediately followed by a NOT. XNOR is equivalent to an XOR immediately followed by a NOT.