And
, Or
, Xor
and Not
I understand. What I don't get are Imp
and Eqv
. What do they mean? How'd they get in there? Is there any real use for them?
VB.NET supports four logical operators: And , AndAlso , Or , OrElse , Not , and Xor .
A logical operator is a symbol or word used to connect two or more expressions such that the value of the compound expression produced depends only on that of the original expressions and on the meaning of the operator. Common logical operators include AND, OR, and NOT.
The Not Operator performs logical negation on a Boolean expression. It yields the logical opposite of its operand. If the expression evaluates to True , then Not returns False ; if the expression evaluates to False , then Not returns True .
IMP is "material implication" "a implies b" or "if a then b", which is equivalent to NOT a OR b. EQV is "equivalence" or "if and only if", so a EQV b is the same as (a IMP b) AND (b IMP a).
They got there because someone wanted to be complete. They can shorten some logical expressions, but you can always express the same thing with NOT and AND, NOT and OR, or with XOR alone.
Here is the truth table for all the operators, both for boolean and for bitwise. The best time to use them is when you map your logic and realize you have a function that takes two inputs, and has the same outputs as those operators:)
------------------------------------------------------------------------------------------------------------------
|AND | | | |OR | | | |XOR | | | |IMP | | | |EQV | | |
------------------------------------------------------------------------------------------------------------------
|In1 |In2 |Out1 | |In1 |In2 |Out1 | |In1 |In2 |Out1 | |In1 |In2 |Out1 | |In1 |In2 |Out1 |
------------------------------------------------------------------------------------------------------------------
|False|False|False| |False|False|False| |False|False|False| |False|False|True | |False|False|True |
------------------------------------------------------------------------------------------------------------------
|False|True |False| |False|True |True | |False|True |True | |False|True |True | |False|True |False|
------------------------------------------------------------------------------------------------------------------
|False|Null |False| |False|Null |Null | |False|Null |Null | |False|Null |True | |False|Null |Null |
------------------------------------------------------------------------------------------------------------------
|True |False|False| |True |False|True | |True |False|True | |True |False|False| |True |False|False|
------------------------------------------------------------------------------------------------------------------
|True |True |True | |True |True |True | |True |True |False| |True |True |True | |True |True |True |
------------------------------------------------------------------------------------------------------------------
|True |Null |Null | |True |Null |True | |True |Null |Null | |True |Null |Null | |True |Null |Null |
------------------------------------------------------------------------------------------------------------------
|Null |False|False| |Null |False|Null | |Null |False|Null | |Null |False|Null | |Null |False|Null |
------------------------------------------------------------------------------------------------------------------
|Null |True |Null | |Null |True |True | |Null |True |Null | |Null |True |True | |Null |True |Null |
------------------------------------------------------------------------------------------------------------------
|Null |Null |Null | |Null |Null |Null | |Null |Null |Null | |Null |Null |Null | |Null |Null |Null |
------------------------------------------------------------------------------------------------------------------
| | | | | | | | | | | | | | | | | | | |
------------------------------------------------------------------------------------------------------------------
|In1 |In2 |Out1 | |In1 |In2 |Out1 | |In1 |In2 |Out1 | |In1 |In2 |Out1 | |In1 |In2 |Out1 |
------------------------------------------------------------------------------------------------------------------
|001 |001 |001 | |001 |001 |001 | |001 |001 |000 | |001 |001 |111 | |001 |001 |111 |
------------------------------------------------------------------------------------------------------------------
|001 |010 |000 | |001 |010 |011 | |001 |010 |011 | |001 |010 |110 | |001 |010 |100 |
------------------------------------------------------------------------------------------------------------------
|001 |011 |001 | |001 |011 |011 | |001 |011 |010 | |001 |011 |111 | |001 |011 |101 |
------------------------------------------------------------------------------------------------------------------
|001 |100 |000 | |001 |100 |101 | |001 |100 |101 | |001 |100 |110 | |001 |100 |010 |
------------------------------------------------------------------------------------------------------------------
|010 |001 |000 | |010 |001 |011 | |010 |001 |011 | |010 |001 |101 | |010 |001 |100 |
------------------------------------------------------------------------------------------------------------------
|010 |010 |010 | |010 |010 |010 | |010 |010 |000 | |010 |010 |111 | |010 |010 |111 |
------------------------------------------------------------------------------------------------------------------
|010 |011 |010 | |010 |011 |011 | |010 |011 |001 | |010 |011 |111 | |010 |011 |110 |
------------------------------------------------------------------------------------------------------------------
|010 |100 |000 | |010 |100 |110 | |010 |100 |110 | |010 |100 |101 | |010 |100 |001 |
------------------------------------------------------------------------------------------------------------------
|011 |001 |001 | |011 |001 |011 | |011 |001 |010 | |011 |001 |101 | |011 |001 |101 |
------------------------------------------------------------------------------------------------------------------
|011 |010 |010 | |011 |010 |011 | |011 |010 |001 | |011 |010 |110 | |011 |010 |110 |
------------------------------------------------------------------------------------------------------------------
|011 |011 |011 | |011 |011 |011 | |011 |011 |000 | |011 |011 |111 | |011 |011 |111 |
------------------------------------------------------------------------------------------------------------------
|011 |100 |000 | |011 |100 |111 | |011 |100 |111 | |011 |100 |100 | |011 |100 |000 |
------------------------------------------------------------------------------------------------------------------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With