# Logic Gates

Boolean algebra is a branch of mathematics that deals with operations on logical values with binary variables. The Boolean variables are represented as binary numbers to represent truths: 1 = True or On and 0 = False or Off. This is also how they are represented in binary.

Logic Gates perform a function on one or more binary inputs and return a single binary output. Logic gates are physically constructed in electronic circuits. However, the same logic can be used when a conditional has 2 inputs and a logic gate such as AND or OR.

# AND Gate

The AND gate takes 2 inputs. It only returns True when both inputs are True.

An example of this is if a person is eligible to vote. The input is whether are they **equal and above voting age** AND **are a citizen.** If any of the inputs are false then they aren't eligible to vote.

# OR Gate

The OR gate also known as an "inclusive or" also take 2 inputs. The output is True if either or both of the inputs are True.

An example of this is if a person is eligible to apply for a job position. The input is whether they **have a degree** OR **have 3 years of work experience.** If the person has either or both they are eligible. Only if they have neither are they not eligible.

# XOR Gate

The XOR (exclusive-OR) gate acts in the same way as the OR Gate except when both inputs are true in which case it returns a false.

An example of this is when you offered 2 options for your meal. The input is whether they **choice one** OR **choice two.** If the person has chosen 1 or 2 they have a meal (True). If they choose neither or both they have no meal (False).

# NOT Gate

The NOT gate also known as logical inverter has only one input. It simply takes the input and reverses it. So true becomes false and false becomes true. The remaining gates are the previous 3 but have a Not Gate directly after the output.

# NAND Gate

The NAND gate operates as an AND gate followed by a NOT gate. It does the AND operation and then takes that output as the input for a not gate which reverses it.

# NOR Gate

The NOR gate operates as an OR gate followed by a Not gate. It does the OR operation and then takes that output as the input for a not gate which reverses it.

# XNOR Gate

The XNOR (exclusive-NOR) gate operates as a NOR gate followed by a Not gate. It does the NOR operation and then takes that output as the input for a not gate which reverses it.

# Calculator using only Logic Gates

Below is a calculator that can add 2 4bit (0-15 in **Base10**) numbers using only **AND** and **XOR** in a certain order. Its doing the calculation 10+7 =17 in binary. If a line is read it is carrying a 1 value and if it is white it is a 0 value.

.