Presentation is loading. Please wait.

Presentation is loading. Please wait.

EMB1006 Boolean Logic Jonathan-Lee Jones.

Similar presentations


Presentation on theme: "EMB1006 Boolean Logic Jonathan-Lee Jones."— Presentation transcript:

1 EMB1006 Boolean Logic Jonathan-Lee Jones

2 Overview What is logic Types of Logic gate Truth Tables
Examples to work through Other Gates Binary Arithmetic Boolean Logic in Programming Boolean Algebra De Morgan’s Laws

3 What is Logic Computers and logic are inseparable - right?
They are now but at the start things were much more hazy. The first computers were conceived as automatic arithmetic engines and while their creators were aware that logic had something to do with it all, they weren’t 100% clear as to the how or why.

4 What is Logic Boolean logic is very easy to explain and to understand.
You start off with the idea that some statement P is either true or false, it can’t be anything in between (this called the law of the excluded middle). Then you can form other statements, which are true or false, by combining these initial statements together using the fundamental operators And, Or and Not.

5 Types of Logic Gate There are THREE types of fundamental Logic gate. These for the basis for Boolean logic. Other gates exist, but these can be made from combining the three fundamental types. AND gates OR gates NOT gates

6 Types of Logic Gate AND Gates These gates give a true (or 1) response if BOTH their inputs are true.

7 Types of Logic Gate OR Gates These gates give a true (or 1) response if EITHER or BOTH their inputs are true.

8 Types of Logic Gate NOT Gates These gates give a true (or 1) response if their input is false. These are known as INVERTERS

9 Truth Tables The rules for combining expressions are usually written down as tables listing all of the possible outcomes. These are called truth tables. They usually use either TRUE of FALSE, or 1 and 0 to represent the data. The truth tables for the three fundamental operators these are:

10 Truth Tables A B O 1 AND Gate A O B

11 Truth Tables A B O 1 AND Gate A O B

12 Truth Tables A B O 1 AND Gate A O B

13 Truth Tables A B O 1 AND Gate A O B

14 Truth Tables A B O 1 AND Gate A O B

15 Truth Tables A B O 1 OR Gate A O B

16 Truth Tables A B O 1 OR Gate A O B

17 Truth Tables A B O 1 OR Gate A O B

18 Truth Tables A B O 1 OR Gate A O B

19 Truth Tables A B O 1 OR Gate A O B

20 Truth Tables A O 1 NOT Gate A O

21 Truth Tables A O 1 NOT Gate A O

22 Truth Tables A O 1 NOT Gate A O

23 Examples A O B C D E A B C D E O

24 Examples A O B C D E A B C D E O

25 Examples A O B C D E A B C D E O 1

26 Examples A O B C D E A B C D E O 1

27 Examples A O B C D E A B C D E O 1

28 Examples A O B C D E A B C D E O 1

29 Examples A O B C D E A B C D E O 1

30 Examples A O B C D E A B C D E O 1

31 Examples A O B C D E A B C D E O 1

32 Examples A D B E O C A B C D E O

33 Examples A D B E O C A B C D E O 1

34 Examples A D B E O C A B C D E O 1

35 Examples A D B E O C A B C D E O 1

36 Examples A D B E O C A B C D E O 1

37 Examples A D B E O C A B C D E O 1

38 Other Gates EOR(XOR) Gates These gates give a true (or 1) response if one of their inputs is TRUE, but not BOTH. They are EXCLUSIVE OR GATES A O B A B O 1

39 Other Gates NAND Gates These gates give a true (or 1) response if BOTH their inputs are 0. They are a combination of A NOT and and AND gate. A O B A B O 1

40 Other Gates NOR Gates These gates give a true (or 1) response if both their inputs are 0. They are the combination of a NOT and an OR gate. A O B A B O 1

41 Binary Arithmetic Boolean logic can be used to implement binary arithmetic. Notice that there is no suggestion that binary arithmetic and Boolean logic are the same thing - they aren’t. Binary arithmetic is just an example of a place value system for representing values. That is, we humans work in base 10 and computers find it easier to work in base two because they don’t have ten fingers.

42 Binary Arithmetic However when you do binary arithmetic you follow standard rules that determine how you should combine bits together to produce result bits. These rule can be expressed as combinatorial logic - in other words a truth table. Buy using a series of gates, it is then possible to carry out some arithmetic procedures.

43 Binary Arithmetic A B RESULT CARRY

44 Binary Arithmetic A B RESULT CARRY 1

45 Binary Arithmetic A B RESULT CARRY 1

46 Binary Arithmetic A B RESULT CARRY 1

47 Binary Arithmetic You can see that this is just another truth table and the combinatorial logic needed for it can be produced in the usual way. Actually this is only a half adder - yes this is the real technical term - in that it doesn’t add a carry bit that might have been generated by a previous pair of bits.

48 Binary Arithmetic The table for a “full adder”, this too is the correct technical term is: A B C RESULT CARRY 1

49 Boolean Logic in Programming
Boolean logic is fundamental to the design of computer hardware even if it isn’t the whole story. The same holds true for programming. A program also needs the element of time built into it to make it work and this takes it beyond the bounds of simple Boolean logic. However there are times when simple common sense reasoning lets even the best programmer down.

50 Boolean Logic in Programming
For example, a common task is making a decision using an IF statement: IF (A>0 AND A<10) THEN do something The bracket following the IF is almost pure Boolean logic and the something only gets done if it works out to be true. So far so simple, so simple in fact that many programmers decide that they don’t need to know anything about Boolean logic at all; a serious error.

51 Boolean Logic in Programming
Consider how you would change this example so that the “something” was done when the condition was false. The simplest way is to write: IF NOT(A>0 AND A<10) THEN do something Instead of using NOT, a programmer wrote the code like this:- IF (A<=0 AND A>=10) THEN do something Is this correct? If not, how would you write the statement without using a NOT?

52 Boolean Logic in Programming
IF (A<=0 AND A>=10) THEN do something This is incorrect. A can never be BOTH less that or equal to 0 AND greater than or equal to 10. The correct NOT of the condition is: IF (A<=0 OR A>10) THEN do something The switch from AND to OR shocks many experienced programmers and it is a source of many programming errors.

53 Boolean Algebra We don’t always draw logic gates for these. In Boolean Algebra we use different symbols to represent the logic. The basic operations of Boolean algebra are as follows. AND (conjunction), denoted x∧y (sometimes x AND y or Kxy), satisfies x∧y = 1 if x = y = 1 and x∧y = 0 otherwise. OR (disjunction), denoted x∨y (sometimes x OR y or Axy), satisfies x∨y = 0 if x = y = 0 and x∨y = 1 otherwise. NOT (negation), denoted ¬x (sometimes NOT x, Nx or !x), satisfies ¬x = 0 if x = 1 and ¬x = 1 if x = 0.

54 Boolean Algebra

55 Boolean Algebra (X or Y) or Z X Y X or Y Z (X or Y) or Z 1

56 Boolean Algebra (X or Y) or Z X Y X or Y Z (X or Y) or Z 1

57 Boolean Algebra X or (Y or Z) X Y Z Y or Z X or (Y or Z) 1

58 De Morgan’s Laws The rules can be expressed in English as:
The negation of a conjunction is the disjunction of the negations. The negation of a disjunction is the conjunction of the negations. or informally as: "not (A and B)" is the same as "(not A) or (not B)" and also, "not (A or B)" is the same as "(not A) and (not B)".


Download ppt "EMB1006 Boolean Logic Jonathan-Lee Jones."

Similar presentations


Ads by Google