Computing - Logic Gates

AQA Computer Science 2022


Logic Gates

NameShape
ANDLike a “D”
ORLike a crescent
NOTLike a triangle with a dot
NANDLike and with a dot
NORLike an OR with a dot
XORLike OR with an extra crescent

AND

Input 1Input 2Output
000
010
100
111

OR

Input 1Input 2Output
000
011
101
111

NOT

Input 1Output
01
10

NAND

AND + NOT

Input 1Input 2Output
001
011
101
110

NOR

OR + NOT

Input 1Input 2Output
001
010
100
110

XOR

OR, but 1 & 1 is 0.

XOR is also sometimes called the NEQ operator, meaning “not equivalent”. This is because you can also describe it as only being true if the operands differ.

Input 1Input 2Output
000
011
101
110

XOR is probably the most popular logical operator in exams. The property that makes this useful is that XOR is like adding two binary numbers together in a single column:

| 0|   | 1|   | 1|
| 0|   | 0|   | 1|
|--|   |--|   |--|
| 0|   | 1|   | 0| (1 carried over)

XOR as an adder

In terms of the operands, how could you describe XOR?

XOR is true if the operands are different.

Why is XOR sometimes called the NEQ operator?

Because it only is true if the operands are different.

What property makes XOR useful?

It’s like adding two binary digits together in a single column.

What is the limitation of XOR as an adder?

It does not deal with carries.

Half-Adders

A one-bit binary adder. This means it can deal with adding two one-bit binary numbers together and dealing with carries.

They take two inputs:

  • A, the first binary digit.
  • B, the second binary digit.

And have two outputs:

  • S, the sum of the two binary digits.
  • C, the carry from the addition if there was one.
ABCS
0000
0101
1001
1110

What is a half adder?

A one bit binary adder.

How many inputs does a half adder have?

2

What inputs does a half adder have?

_ _ A _ _ and _ _ B _ _ , two binary digits.

How many outputs does a half adder have?

2

What outputs does a half adder have?

  • _ _ S _ _ , the sum of the binary digits.
  • _ _ C _ _ , the carry from the sum if there was one.

How is a half adder constructed?

What is the limitation of a half adder?

Although it outputs a carry, it cannot take a carry as input.

What is a half adder that can take a carry as an input called?

A full adder.

How many XOR gates does a half adder have?

1

How many AND gates does a half adder have?

1

How many OR gates does a half adder have?

None!

How many NOTs does a half adder have?

None!

Full Adders

Full adders take three inputs:

  • A, one bit
  • B, one bit
  • C in, a carry bit

They have two outputs:

  • Sum, the result of adding the two bits and the carry (think “left hand column”)
  • C out, the carry.
ABC inC outSum
00000
00101
01001
01110
10001
10110
11010
11111

Notice how the truth table is just like adding three numbers together. You can think of a full adder as a half adder that then has to deal with a carry in bit too. There’s this really beautiful way that a full adder is actually just two half adders and an OR gate and it’s in my head but I can’t get it out.

How can you conceptualize a full adder in the context of a half adder?

A full adder is like a half adder that then has to deal with a carry in bit.

How is a full adder constructed?

How many XOR gates in a full adder?

2

How many AND gates in a full adder?

2

How many OR gates in a full adder?

1

How many NOTs in a full adder?

None!

How many inputs does a full adder have?

3

How many outputs does a full adder have?

2

What are the inputs to a full adder?

  • _ _ A _ _ , a binary digit
  • _ _ B _ _ , a binary digit
  • _ _ C in _ _ , the carry in

What outputs does a full adder have?

  • _ _ S _ _ , the sum
  • _ _ C out _ _ , the carry from the addition if there was one.

Why is it important to have a carry in and a carry out in a full adder?

Because adders for multiple bits work as a chain, where the previous carry out is passed on as the carry in.

How can you create a multiple bit adder?

  • Visualise the multiple bits as two columns, one for each number.
  • The first column only needs to be a half-adder because there’s no carry in.
  • The rest of the columns are full adders, taking the two bits from that column and the previous carry out.

In what way is a full adder two half-adders and an OR gate?

  • Inputs A and B are run through a half adder, if this overflows then a carry is needed
  • The sum of A and B and the carry in are run through a half adder, if this overflows then a carry is needed