Difference between revisions of "And"
(→comparative remarks: correct wrong statement) |
(clean a bit and add cat) |
||
Line 1: | Line 1: | ||
{{And}} | {{And}} | ||
− | The binary operator | + | The binary operator {{HL|and}} performs a logical conjunction. |
− | [[FPC]] also does a bitwise | + | [[FPC]] also does a bitwise {{HL|and}} when supplied with ordinal types. |
== Boolean operation == | == Boolean operation == | ||
− | The operator | + | The operator {{HL|and}} accepts to two Boolean type values. |
It is the logical conjunction written in classic logic as <math>A \land B</math>. | It is the logical conjunction written in classic logic as <math>A \land B</math>. | ||
Electrical engineers may write <math>A \times B</math> or <math>A \cdot B</math>, or eliminating the multiplication sign altogether writing <math>AB</math>. | Electrical engineers may write <math>A \times B</math> or <math>A \cdot B</math>, or eliminating the multiplication sign altogether writing <math>AB</math>. | ||
However, the [[*|asterisk]] has a different meaning in programming. | However, the [[*|asterisk]] has a different meaning in programming. | ||
− | The Boolean | + | The Boolean {{HL|and}} evaluates to [[false and true|{{HL|true}}]] if and only if both operands are {{HL|true}}. |
{| class="wikitable" style="text-align:center; margin:auto;" | {| class="wikitable" style="text-align:center; margin:auto;" | ||
− | ! | + | ! {{HL|A}} |
− | ! | + | ! {{HL|B}} |
− | ! | + | ! {{HL|A or B}} |
|- | |- | ||
− | | | + | | {{HL|false}} |
− | | | + | | {{HL|false}} |
− | | style="background: #eeeeee" | | + | | style="background: #eeeeee" | {{HL|false}} |
|- | |- | ||
− | | | + | | {{HL|false}} |
− | | | + | | {{HL|true}} |
− | | style="background: #eeeeee" | | + | | style="background: #eeeeee" | {{HL|false}} |
|- | |- | ||
− | | | + | | {{HL|true}} |
− | | | + | | {{HL|false}} |
− | | style="background: #eeeeee" | | + | | style="background: #eeeeee" | {{HL|false}} |
|- | |- | ||
− | | | + | | {{HL|true}} |
− | | | + | | {{HL|true}} |
− | | style="background: #eeeeee" | | + | | style="background: #eeeeee" | {{HL|true}} |
|+ truth table for logical conjunction | |+ truth table for logical conjunction | ||
|} | |} | ||
Line 43: | Line 43: | ||
== comparative remarks == | == comparative remarks == | ||
− | Depending on the compiler's specific implementation of the data type [[Set| | + | Depending on the compiler's specific implementation of the data type [[Set|{{HL|set}}]], the [[Asterisk|intersection of sets]] virtually does the same as the bitwise {{HL|and}}. |
== see also == | == see also == | ||
− | * [[Or| | + | * [[Or|{{HL|or}}]] |
+ | [[Category:Operators]] |
Revision as of 18:45, 15 October 2020
│
Deutsch (de) │
English (en) │
español (es) │
suomi (fi) │
français (fr) │
русский (ru) │
The binary operator and
performs a logical conjunction.
FPC also does a bitwise and
when supplied with ordinal types.
Boolean operation
The operator and
accepts to two Boolean type values.
It is the logical conjunction written in classic logic as [math]\displaystyle{ A \land B }[/math].
Electrical engineers may write [math]\displaystyle{ A \times B }[/math] or [math]\displaystyle{ A \cdot B }[/math], or eliminating the multiplication sign altogether writing [math]\displaystyle{ AB }[/math].
However, the asterisk has a different meaning in programming.
The Boolean and
evaluates to true
if and only if both operands are true
.
A
|
B
|
A or B
|
---|---|---|
false
|
false
|
false
|
false
|
true
|
false
|
true
|
false
|
false
|
true
|
true
|
true
|
Bitwise operation
FPC also defines a bitwise and
.
Taking two ordinal operands logical and
is calculated bit by bit:
1010'1100 and 0011'0100 ―――――――――――― 0010'0100
comparative remarks
Depending on the compiler's specific implementation of the data type set
, the intersection of sets virtually does the same as the bitwise and
.