1.9 Logic Gates and Computer Math
- ⭐️ not in exam
📌 Table
2 inputsand1 outcome2 inputs:A,B1 outcome:Y
✅ AND
outcome 1only when both input is1 & 1- symbol: semi circle
✅ OR
outcome 1only when any input is1- symbol: rounded, curved triangle
✅ XOR
Exclusive OR
outcome 1only when one input is1- symbol: rounded, curved triangle with a curved line
- When there is too much electricity, the whole electricity goes off
- does not like too much
1s - 🛠️ Used in CRC code
- 🛠️ Used in salt
✅ NOT
gate that makes the opposite
- ↔️ only
one inputandone output - symbol: triangle
✅ NAND
opposite of AND
NOT AND
- outcome is opposite of
AND - draw
ANDand make opposite - symbol:
ANDwith a small circle, likeNOT
1
2
3
00 ➡️ 1
01 ➡️ 1
10 ➡️ 1
- following the three first outputs,
- NAND is a gate that is active when smth is OFF
- When I unplug my
USB(off), the data is not lost, data is active - even when unplugged, the information is active
- so even when USB is unplugged,
1, which is5vis active even when it is not connected to any electricity - 🛠️ Thanks to
NAND, we can have USB and SSDs NANDgates produces electrocity even when it is not plugged to electricity
✅ NOR
opposite of OR
- draw
ORand make opposite symbol:
ORwith a small circle, likeNOTNORgate produces electricity when it is unplugged- when it is
0, 0result is1 - but when it is plugged, cuts off the electricity
- ⚠️
NORgate will save information when it is off, disconnected - but they will lose information when conected
- when you connect/plug in, you delete/destroy data
- Thus, not valid for USBs
- 🛠️ Perfect for hardware malware
- create malware with hardware, so if somebody plugs in, you destroy all the information in his computer
✅ Shift Gate
moves the bits to the right
1
2
3
if 00010000 = 16
with shift gate
result will be 00001000 = 8
- 🛠️ Gate used for dividing in two
- Many dividing mathematical operations are done by
Shift Gate
✅ Design gates
- normally gates come in groups
- 4
ANDs - 4
NANDs 4
NANDswith shift function- Logic gates are inside the micro processor/micro chip
- 🛠️ For doing all the mathematical operations for the computer
📌 How the computer adds
- we need to add in binary
computer adds using
XORandANDuseXORfor0+0, 0+1, 1+0and useANDfor carrying
1
2
3
4
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0, and carry 1
- Looks exactly like
XOR - Thus, add is done by
XORgate when you buy
XORgate, your computer is adding- we carry
1when there aretwo 1s - Thus,
1 + 1carrying is done byAND
1
2
3
4
5
01011111 + 00110011
computer adds bit by bit
starting from the right
- 1+1 result will be 0, and carry 1
👉🏻 10010010
- we might carry
1 + 1at the very left end - if that happens, we add the
1at the right and add again so it might look like
1looks small, but this is how computer adds- 🛠️ When I use google maps, play games I am adding/substracting
- going closer: substracting distance, go further: add distance
📌 How the computer substracts
- for substraction, computer uses
NOTand all the circuits for adding - for substraction, computer uses
NOTandXORandAND - the computer needs 2
XORs, 1ANDand 1NOT - so substraction needs more gates
- due to this, in programming, we try to do more adding then substraction
if possible, we try to do more adding
- 1️⃣ We keep the first number exactly the way it is
- 2️⃣ we make the second number negative, use
NOT - 3️⃣ then we add both
1
2
3
4
15 - 12
1️⃣ 15
2️⃣ 12 ➡️ -12
3️⃣ = 15 + (-12)
1
2
3
4
5
010111 - 101011
1️⃣ 010111
2️⃣ 010100
3️⃣ 010111 + 010100 = 101011
👉🏻 101011
- 🛠️ Micro programming would be done in binary
- so adding, substraction would be done in Micro programming, in binary
- prefer adding
This post is licensed under CC BY 4.0 by the author.



