Binary logical operations, also known as boolean operations, allow the manipulation and analysis of conditions within digital systems.

They are called logical operations because they **show parallels with “traditional logic”**, where there are operations such as AND, OR, and NOT, represented by symbols like ”∧”, ”∨”, and ”¬“.

In the field of logical operations, **we treat the bits as boolean values**. In other words, in these operations, we will consider that `0`

is false, and `1`

is true.

On the other hand, logical operations operate at an individual level of each bit of the binary number. We call this “bitwise” operations (bit-by-bit operation).

## AND Operation (Logical AND)

The AND operation takes two bits as input and produces an output bit that is 1 **if and only if both input bits are 1**. The truth table for the AND operation is as follows:

A | B | A AND B |
---|---|---|

0 | 0 | 0 |

0 | 1 | 0 |

1 | 0 | 0 |

1 | 1 | 1 |

We call it the “AND” operation because the concept is similar to what we have in our heads with the “and” concept.

A and B are true if both A and B are true

To apply it to binary numbers, we perform the “bitwise” operation, that is, for each bit individually.

```
1010
AND
1100
=
1000
```

Since only the bits that are true in both input numbers remain on in the result.

## OR Operation (Logical OR)

The OR operation takes two bits as input and produces an output bit that is 1 **if at least one of the input bits is 1**. The truth table for the OR operation is as follows:

A | B | A OR B |
---|---|---|

0 | 0 | 0 |

0 | 1 | 1 |

1 | 0 | 1 |

1 | 1 | 1 |

Which as we see corresponds to the “OR” concept we have in our heads.

A or B is true, if A happens or if B happens

If we apply it to binary numbers, we again perform the “bitwise” operation. For example,

```
1010
OR
1100
=
1110
```

## NOT Operation (Logical NOT)

The NOT operation takes a single bit as input and produces an output bit that is **the complement of the input bit**. That is, if the input bit is `0`

, the output bit will be `1`

, and vice versa.

The truth table for the NOT operation is as follows:

A | NOT A |
---|---|

0 | 1 |

1 | 0 |

Applied bitwise in binary numbers

```
1010
=
0101
```

For example, in the binary operation `NOT 1010`

, the result would be `0101`

, since all input bits are inverted in the result.

## Other logical operations

The previous operations are the fundamental ones in a logical system. However, there are others that we will sometimes find, although less frequently.

### NAND Operation (NOT AND)

The NAND operation is the negation of the AND operation. That is, it returns false if both operands are true, and true in all other cases.

A | B | A NAND B |
---|---|---|

0 | 0 | 1 |

0 | 1 | 1 |

1 | 0 | 1 |

1 | 1 | 0 |

It is equivalent to:

### NOR Operation (NOT OR)

The NOR operation is the negation of the OR operation. It returns true if both operands are false, and false in all other cases.

A | B | A NOR B |
---|---|---|

0 | 0 | 1 |

0 | 1 | 0 |

1 | 0 | 0 |

1 | 1 | 0 |

It is equivalent to:

### XOR Operation (Exclusive OR)

The XOR operation, also known as “Exclusive OR,” returns true if exactly one of the operands is true, and false if both are equal.

A | B | A XOR B |
---|---|---|

0 | 0 | 0 |

0 | 1 | 1 |

1 | 0 | 1 |

1 | 1 | 0 |

It is equivalent to:

### XNOR Operation (NOT Exclusive OR)

The XNOR operation is the negation of XOR. It returns true if both operands are equal, and false if they are different.

A | B | A XNOR B |
---|---|---|

0 | 0 | 1 |

0 | 1 | 0 |

1 | 0 | 0 |

1 | 1 | 1 |

It is equivalent to: