Skip to content

Latest commit

 

History

History
135 lines (108 loc) · 4.95 KB

Logical operations on bits.md

File metadata and controls

135 lines (108 loc) · 4.95 KB

Logical operations on bits are fundamental operations in digital electronics and computer science. They operate on binary data, manipulating individual bits according to specific rules. The most common logical operations are AND, OR, NOT, NAND, NOR, XOR, and XNOR. Here’s a detailed look at each of these operations:

1. AND Operation

  • Symbol: & or

  • Operation: The AND operation results in 1 if both input bits are 1; otherwise, it results in 0.

  • Truth Table:

    A B A AND B (A & B)
    0 0 0
    0 1 0
    1 0 0
    1 1 1
  • Example:
    ( 1 & 1 = 1 )
    ( 1 & 0 = 0 )

2. OR Operation

  • Symbol: | or +

  • Operation: The OR operation results in 1 if at least one of the input bits is 1; otherwise, it results in 0.

  • Truth Table:

    | A | B | A OR B (A | B) | |---|---|----------------| | 0 | 0 | 0 | | 0 | 1 | 1 | | 1 | 0 | 1 | | 1 | 1 | 1 |

  • Example:
    ( 1 | 0 = 1 )
    ( 0 | 0 = 0 )

3. NOT Operation

  • Symbol: ¬ or !

  • Operation: The NOT operation (also called negation) inverts the value of the bit; it results in 1 if the input is 0 and 0 if the input is 1.

  • Truth Table:

    A NOT A (¬A)
    0 1
    1 0
  • Example:
    ( ¬1 = 0 )
    ( ¬0 = 1 )

4. NAND Operation

  • Symbol: or A NAND B

  • Operation: The NAND operation is the negation of the AND operation. It results in 0 only if both inputs are 1; otherwise, it results in 1.

  • Truth Table:

    A B A NAND B (A ↑ B)
    0 0 1
    0 1 1
    1 0 1
    1 1 0
  • Example:
    ( 1 \uparrow 1 = 0 )
    ( 1 \uparrow 0 = 1 )

5. NOR Operation

  • Symbol: or A NOR B

  • Operation: The NOR operation is the negation of the OR operation. It results in 1 only if both inputs are 0; otherwise, it results in 0.

  • Truth Table:

    A B A NOR B (A ↓ B)
    0 0 1
    0 1 0
    1 0 0
    1 1 0
  • Example:
    ( 0 \downarrow 0 = 1 )
    ( 1 \downarrow 0 = 0 )

6. XOR (Exclusive OR) Operation

  • Symbol:

  • Operation: The XOR operation results in 1 if exactly one of the inputs is 1; otherwise, it results in 0.

  • Truth Table:

    A B A XOR B (A ⊕ B)
    0 0 0
    0 1 1
    1 0 1
    1 1 0
  • Example:
    ( 1 \oplus 0 = 1 )
    ( 1 \oplus 1 = 0 )

7. XNOR (Exclusive NOR) Operation

  • Symbol:

  • Operation: The XNOR operation is the negation of the XOR operation. It results in 1 if both inputs are the same; otherwise, it results in 0.

  • Truth Table:

    A B A XNOR B (A ⊙ B)
    0 0 1
    0 1 0
    1 0 0
    1 1 1
  • Example:
    $( 1 \odot 1 = 1 )$
    $( 0 \odot 1 = 0 )$

Summary of Logical Operations

Operation Symbol Result Conditions
AND & 1 if both inputs are 1
OR | 1 if at least one input is 1
NOT ¬ 1 if input is 0, 0 if input is 1
NAND 1 unless both inputs are 1
NOR 1 only if both inputs are 0
XOR 1 if exactly one input is 1
XNOR 1 if both inputs are the same

Applications of Logical Operations

  1. Digital Circuit Design: Logical operations are fundamental in creating circuits for computers, microcontrollers, and other electronic devices.
  2. Programming: Logical operators are used in conditional statements, loops, and logical evaluations in programming languages.
  3. Data Processing: They are used in algorithms for data manipulation, searching, and sorting.
  4. Error Detection: Logical operations are integral to error detection and correction codes in data transmission.
  5. Cryptography: Logical operations play a key role in cryptographic algorithms and security protocols.

Conclusion

Logical operations on bits are essential for understanding and designing digital systems. They form the basis for various applications in computer science, electronics, and information technology. Mastering these operations is crucial for anyone working in these fields.