Logic

Understanding how binary logic works will help your programming. In your programming you often use complex boolean expressions to control loops and selection statements, for example:

While x<=10 AND OR y>=11 (programme continues until X equal to or greater than 10 And/Or Y is greater than or equal to [therefore true] )

In this example the Boolean expression has been swapped for a letter.

Alternatively

Until input = Y then (this code will test if Y is true and when it is will then escape or perform another function within the programme)

if total <= 10:

print("your current contract is right for you")

else:

print("you may want to consider another contract")

In this loop the programme checks if total  is either equal to or less than 10. The programme will continue to loop until total equals 10.

Boolean Data types in programming are either true or false, x or y are either true or false. To translate this to Boolean logic true is equal to 1/ON and false is equal to 0/OFF. This can be represented with switches which are either open or closed.

There are three main types of logic gate that you need to know.

NOT gate

 Input A Output Q 1 0 0 1

In this image a NOT gate is shown, the truth table shows the outcome. If the Input is 1 the Output is 0.

AND gate

 Input A Input B Output Q 0 0 0 1 0 0 0 1 0 1 1 1

In this image an AND gate is shown, the truth table shows the outcome. Both Input A and Input B must both be 1/ON to get an Output of 1.

OR gate

 Input A Input B Output Q 0 0 0 1 0 1 0 1 1 1 1 1

In this image an OR gate is shown, the truth table shows that provided at least one Input is ON/1 then the Output is ON/1.

Boolean Logic & Logic Gates