Difference between revisions of "And"

From Free Pascal wiki
Jump to navigationJump to search
Line 35: Line 35:
  
 
== Bitwise operation ==
 
== Bitwise operation ==
FPC also defines a bitwise <syntaxhighlight lang="pascal" enclose="none">and</syntaxhighlight>.
+
FPC also defines a bitwise <syntaxhighlight lang="pascal" inline>and</syntaxhighlight>.
Taking two ordinal operands logical <syntaxhighlight lang="pascal" enclose="none">and</syntaxhighlight> is calculated bit by bit:
+
Taking two ordinal operands logical <syntaxhighlight lang="pascal" inline>and</syntaxhighlight> is calculated bit by bit:
 
     1010'1100
 
     1010'1100
 
  and 0011'0100
 
  and 0011'0100

Revision as of 17:17, 6 August 2022

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 and B
false false false
false true false
true false false
true true true
truth table for logical conjunction

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.


navigation bar: Pascal logical operators
operators

and • or • not • xor
shl • shr
and_then (N/A)• or_else (N/A)

see also

{$boolEval} • Reference: § “boolean operators” • Reference: § “logical operators”