What is the difference between the logical operators NOT, AND and OR?

Asked

Viewed 8,005 times

1

I’m studying Boolean algebra and about logic gates, and I know that these logic operators and logic gates are used in digital systems, programming and electronics. The 3 main operators of Boolean algebra are the operators NOT, AND and OR.

What is the difference between the logical operators NOT, AND and OR? And what is the difference between the logical gates?

  • 1

    I think this question seems to have more to do with electronics than with programming.

  • 1

    But gate logic has to do with introduction to electronics.

  • 2
  • 2

    It’s the same thing. Only logic ports are hardware implementations using transistors and logical operators are software implementations that use processor registers.

  • 1

    Now that you have an answer, you can harm her even more, if she runs away from what was answered.

  • 2

    I think it’s interesting for the programmer to understand how logic gates work, I believe that getting a sense of how things work can help in some situations, often during programming we are used to using a lot OR and E as conditional, and in some cases, the implementation of a XOR port can solve a problem that locks us.

  • 4

    In my opinion you shouldn’t change your question. Anyone who does computing usually has a Computer Architecture subject where they superficially study logic gates. I don’t think it’s duplicated either. The reply @Avelino gave in the comment is already an answer in itself and should be posted as such.

  • 2

    I will add the difference between logical ports and logical operators here

Show 3 more comments

2 answers

7

Wikipedia:

Logical operators

AND, NAND, OR, XOR and NOT are the main logical operators, basis for the construction of digital systems and propositional logic, and also widely used in programming language. The operators AND, NAND, OR and XOR are binary operators, that is, they need two elements, while NOT is unary. In computation, these elements are usually binary variables, whose possible assigned values are 0 or 1. However, the logic used for these variables also serves for sentences (sentences) of the human language, where if this is true corresponds to the value 1, and if false is 0.

  • AND

    Logical operator in which the operation response is true (1) if both input variables are true.

    x1  x2  x1 AND x2   
    0   0   0   
    0   1   0   
    1   0   0   
    1   1   1   
    
  • NAND

    Logical operator in which the operation response is true (1) if at least one of the variables is false.

    x1  x2  x1 NAND x2  
    0   0   1   
    0   1   1   
    1   0   1   
    1   1   0   
    
  • OR

    Logical operator in which the operation response is true (1) if at least one of the input variables is true.

    x1  x2  x1 OR x2    
    0   0   0   
    0   1   1   
    1   0   1   
    1   1   1   
    
  • XOR

    Logical operator in which the operation response is true (1) when variables assume different values from each other.

    x1  x2  x1 XOR x2   
    0   0   0   
    0   1   1   
    1   0   1   
    1   1   0   
    
  • NOT

    Logical operator representing the negation (inverse) of the current variable. If it is true, it becomes false, and vice versa

    x1  NOT x1  
    0   1   
    1   0   
    

Source: https://pt.wikipedia.org/wiki/Operador_lógico

Logic gate

I find this subject off-topic, because even if it has some context similar to programming I still do not know if it is totally comprehensive, although doubts of algorithms are accepted, yet the doubt is not about a specific algorithm, Yet only to make a difference:

Logic gates or logic circuits are devices that operate one or more logic input signals to produce one and only one output, dependent on the function implemented in the circuit. They are usually used in electronic circuits, because of the situations that the signals of this type of circuit may present: presence of signal, or "1"; and absence of signal, or "0". The situations "Truth" and "False" are studied in Mathematical Logic or Boole Logic; origin of the name of these gates. The behavior of logic gates is known by the truth table that presents the logical states of inputs and outputs.

  • AND

    AND

    ENTRADA SAÍDA
    A   B   A AND B
    0   0   0
    0   1   0
    1   0   0
    1   1   1
    
  • OR

    OR

    ENTRADA SAÍDA
    A   B   A OR B
    0   0   0
    0   1   1
    1   0   1
    1   1   1
    
  • NOT

    not

    ENTRADA SAÍDA
    A   NOT A
    0   1
    1   0
    
  • NAND

    NAND

    ENTRADA SAÍDA
    A   B   A NAND B
    0   0   1
    0   1   1
    1   0   1
    1   1   0
    
  • NOR

    NOR

    ENTRADA SAÍDA
    A   B   A NOR B
    0   0   1
    0   1   0
    1   0   0
    1   1   0
    
  • XOR

    XOR

    ENTRADA SAÍDA
    A   B   A XOR B
    0   0   0
    0   1   1
    1   0   1
    1   1   0
    
  • XNOR

    XNOR

    ENTRADA SAÍDA
    A   B   A XNOR B
    0   0   1
    0   1   0
    1   0   0
    1   1   1
    

Source: https://en.wikipedia.org/wiki/Logic_gate

2

The difference is in the conditions of true, AND(E) returns true if the two entries are true, OR(OR) returns true if at least one of the entries is true (one OR another), NOT(NOT) simply reverses the result, that is, if the entry is true it returns false and vice versa.

In the case of logical ports, the ports will handle the input Bites, for example (Run the code to better view):

AND
<table>
  <tr>
    <td>ENTRADA 1</td>
    <td>ENTRADA 2</td>
    <td>RESULTADO</td>
  </tr>
  <tr>
    <td>1 (verdadeiro)</td>
    <td>1 (verdadeiro)</td>
    <td>1 (verdadeiro)</td>
  </tr>
   <tr>
    <td>1 (verdadeiro)</td>
    <td>0 (falso)</td>
    <td>0 (falso)</td>
  </tr>
   <tr>
    <td>0 (falso)</td>
    <td>0 (falso)</td>
    <td>0 (falso)</td>
  </tr>
  <tr>
    <td>0 (falso)</td>
    <td>1 (verdadeiro)</td>
    <td>0 (falso)</td>
  </tr>
  </table>
<br/>

OR
<table>
  <tr>
    <td>ENTRADA 1</td>
    <td>ENTRADA 2</td>
    <td>RESULTADO</td>
  </tr>
  <tr>
    <td>1 (verdadeiro)</td>
    <td>1 (verdadeiro)</td>
    <td>1 (verdadeiro)</td>
  </tr>
   <tr>
    <td>1 (verdadeiro)</td>
    <td>0 (falso)</td>
    <td>1 (verdadeiro)</td>
  </tr>
   <tr>
    <td>0 (falso)</td>
    <td>0 (falso)</td>
    <td>0 (falso)</td>
  </tr>
  <tr>
    <td>0 (falso)</td>
    <td>1 (verdadeiro)</td>
    <td>1 (verdadeiro)</td>
  </tr>
  </table>
<br/>
NOT
<table>
  <tr>
    <td>ENTRADA 1</td>
    <td>RESULTADO</td>
  </tr>
  <tr>
    <td>1 (verdadeiro)</td>
    <td>0 (falso)</td>
  </tr>
   <tr>
    <td>0 (falso)</td>
    <td>1 (verdadeiro)</td>
  </tr>
  </table>
  
  

With these ports you can do some others, being the most common NAND (which returns true if the two entries are false) and XOR (Or unique, which returns true if only one of the entries is true, if both are false returns.)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.