Language: EN

operaciones-logicas-en-binario

What are and how to use logical operations in binary

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

In the context of logical operations, we will treat bits as boolean values. That is, in these operations we will consider that 0 is false, and 1 is true.

On the other hand, logical operations operate at the individual level of each bit of the binary number. We call this “bitwise” operations.

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 ”¬“.

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:

ABA AND B
000
010
100
111

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

A and B is true if both A and B are true.

To apply it to binary numbers, we perform the bitwise operation (that is, on 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:

ABA OR B
000
011
101
111

As we see, it corresponds to the concept of “or” that we have in our minds.

A or B is true if either A is true or B is true.

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:

ANOT A
01
10

Applied bitwise on 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 fundamental in a logical system. However, there are others that we will occasionally encounter (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.

ABA NAND B
001
011
101
110

It corresponds 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.

ABA NOR B
001
010
100
110

It corresponds 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.

ABA XOR B
000
011
101
110

It corresponds 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.

ABA XNOR B
001
010
100
111

It corresponds to: