## 2.4 - Logic

In this section (click to jump):

- Why data is represented in Binary form
- Logic Gates and Truth Tables
- Simple Circuits

## Why data is represented in binary form

This is George Boole. You've probably only ever heard of him when I've been rambling on about him in class, but all of our futures were changed by this man in 1854 when he published a paper which contained "Boolean Logic." The rules he proposed became the "basis of all reasoning" in our computer systems and yet they are based on nothing more than (loosely) AND means multiply and OR means add together. How, er, logical!

Now you've all heard of the Boolean data type - True or False. Boolean logic takes this idea and creates some rules that take one or two inputs and tells you exactly what the "result" of combining these inputs together are. The output is always True or False. (Richtig oder Falsch in German, I always did love those words.)

That sounds complicated, but really it isn't. The complicated part is remembering them off the top of your head - but don't worry, there's a technique for that.

Each Boolean rule is written out in a table form, these are called "truth tables." Cos they is the truth - bare mans swear down, bruv.

These truth tables represent one boolean operation - AND, OR and NOT. Each of these can be represented by a symbol which, in turn is often called a "logic gate". Why a gate? Well they kind of operate like a really weird bouncer at an exceptionally furry toothed geek convention. If you arrive in the right order, they'll let you in, otherwise they won't.

The reason we use these truth tables or logic gates is because they are 100% predictable. We know

And this (starting a sentence with and? Your English teachers are crying out in anguish) is why we use binary in computer systems. Not because its fun, not to satisfy the sadistic needs of weird, pale looking geeks, but because it works and we can prove it. Oh and we can make everything out of switches. That too. That really helps.

Computers represent (or require) data in binary form as they are electronic devices. This is because their circuits are made up of transistors, which are switches that use electric current to change states. A switch can only be in one of two states - on or off. Therefore, all data in a computer is represented as a series of switches in an on or off position, which we interpret as 1 or 0.

Now you've all heard of the Boolean data type - True or False. Boolean logic takes this idea and creates some rules that take one or two inputs and tells you exactly what the "result" of combining these inputs together are. The output is always True or False. (Richtig oder Falsch in German, I always did love those words.)

That sounds complicated, but really it isn't. The complicated part is remembering them off the top of your head - but don't worry, there's a technique for that.

Each Boolean rule is written out in a table form, these are called "truth tables." Cos they is the truth - bare mans swear down, bruv.

These truth tables represent one boolean operation - AND, OR and NOT. Each of these can be represented by a symbol which, in turn is often called a "logic gate". Why a gate? Well they kind of operate like a really weird bouncer at an exceptionally furry toothed geek convention. If you arrive in the right order, they'll let you in, otherwise they won't.

**This leads us to why computers only understand data represented in binary form...**The reason we use these truth tables or logic gates is because they are 100% predictable. We know

*exactly*what we're going to get in any situation. This is incredibly important, literally life or death important in modern computer systems. So we use boolean logic because:- We know the result for any given input
- We know how the circuit will behave in
*all circumstances - there are no hidden surprises.* - We can combine these rules together to perform complex operations (make circuits that do things we want)
- We can use further logic to simplify our designs and save lots of money in manufacturing costs
- We can prove, with 100% certainty, that a circuit does what we say it will using Logical Proofs. You won't need to do this. Probably ever, and if you do you won't be worried because you'll be minted.

And this (starting a sentence with and? Your English teachers are crying out in anguish) is why we use binary in computer systems. Not because its fun, not to satisfy the sadistic needs of weird, pale looking geeks, but because it works and we can prove it. Oh and we can make everything out of switches. That too. That really helps.

**So, let's finish with an exam style definition:**Computers represent (or require) data in binary form as they are electronic devices. This is because their circuits are made up of transistors, which are switches that use electric current to change states. A switch can only be in one of two states - on or off. Therefore, all data in a computer is represented as a series of switches in an on or off position, which we interpret as 1 or 0.

## Logic Gates/Truth Tables

Lets be clear before we start:

These terms are interchangeable and you should be comfortable with either. So sometimes I may say "true" and others "1." Confused? Good. In all seriousness, OCR have a habit of using either words or numbers in truth tables and the like so you need to understand both.

**TRUE = 1**

FALSE = 0FALSE = 0

These terms are interchangeable and you should be comfortable with either. So sometimes I may say "true" and others "1." Confused? Good. In all seriousness, OCR have a habit of using either words or numbers in truth tables and the like so you need to understand both.

## NOT

**What does it do?**Inverts the input, flips it, turns it over, gives it an identity crisis.

**Remember it like this:**"The output is

**NOT**the input."

**Explanation:**The NOT gate simply takes whichever bit you put in and gives you the opposite. It only takes one input, which can either be a 1 or a 0 (because we're working in binary, right, and one bit can be a 0 or 1?)

**Other symbols: NOT can be written like this "¬A" or with a line over the top of a letter.**

## AND

**What does it do?**Tells you when two things are true, tells you when something is switched on or off, multiplies 2 bits.

**Remember it like this:**"one

**AND**the other input must be true, to get true output"

**Explanation:**The AND gate will only give out a true (1) if both of the inputs are also true. This is dead useful for finding out the state of switches in a system/circuit or for only doing something when two things are ready, or for... the list goes on

**Other Symbols: AND**can be written as a full stop - A.B means A AND B. You may also see this symbol being used: A ∧ B which looks a little like an upside down V and means the same thing - A AND B.

## OR

**What does it do?**Tells you if one of the inputs is true or not. More importantly it forms the basis of addition in binary.

**Remember it like this:**"one

**OR**the other input must be true, to get true output"

**Explanation:**The OR gate will give true if any of the inputs are true. This is the easiest rule to learn because all you have to remember is if there's a 1 anywhere, then you'll get a 1 out.

**Other Symbols:**Strangely,

**OR**can be written using a + symbol, so A+B means A OR B. You may also see this symbol being used: A ∨ B which looks just like a V and means the same as before.

## A few tips before we go any further...

We are going to draw many truth tables. Indeed, the truth tables for each individual logic gate is only the beginning.

A few things to remember/understand:

A few things to remember/understand:

- A logic gate is a circuit
- A logic gate has a truth table
- If we combine gates to make a circuit, then this whole circuit has a truth table too!
- We must always include every possible input to a truth table, so we work out what the highest number those binary bits could represent and add one for the combination of 0:
- 2 inputs = (1 + 2) + 1 = 4 possible input combinations (Just like AND and OR gates have)
- 3 inputs = (1 + 2 + 4) + 1 = 8 possible input combinations
- 4 inputs = (1 + 2 + 4 + 8) + 1 = 16 possible input combinations

- You'll never do complicated circuits in the exam, but being able to draw the truth table for a circuit with up to 4 inputs would be an incredible help

## Drawing Truth Tables

Drawing truth tables is actually really easy

The rules for making circuit truth tables are:

That doesn't sound too simple, does it? Let's make a video!

**IF**you break the problem down. If you're good at this and you've remembered all the rules you may well be thinking "don't be silly, I can do it in my head" and you probably can but remember, in an exam situation you want to be using techniques and methods that*guarantee*the marks, whether you're a genius or not. Also you will fail hard for any circuit with more than 2 inputs or 2 or 3 gates.The rules for making circuit truth tables are:

- Write out all of the inputs (e.g. A, B, C)
- Write out all the possible inputs (all the combinations of 0 and 1 that they can be). This is trivial - just count up in binary from 0.
- Now identify all the points on the circuit where there is an output (after each symbol!) if it isn't marked with a letter, make one up yourself.
- Write out each of these points as a column on the table
- Now work your way through the circuit, using the outputs from previous columns as inputs wherever necessary.

That doesn't sound too simple, does it? Let's make a video!