And: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | The binary operator `and` performs a logical conjunction. [[FPC]] also does a bitwise `and` when supplied with ordinal types. | |
| 2 | 2 | ||
| 3 | 3 | ## Boolean operation | |
| 4 | 4 | ||
| 5 | 5 | The operator `and` accepts to two Boolean type values. It is the logical conjunction written in classic logic as $`A \land B`$. Electrical engineers may write $`A \times B`$ or $`A \cdot B`$, or eliminating the multiplication sign altogether writing $`AB`$. However, the [[*|asterisk]] has a different meaning in programming. The Boolean `and` evaluates to [[false and true|true]] if and only if both operands are `true`. | |
| 6 | 6 | ||
| 7 | 7 | | `A` | `B` | `A and B` | | |
| 8 | 8 | |---------|---------|-----------| | |
| 9 | 9 | | `false` | `false` | `false` | | |
| 10 | 10 | | `false` | `true` | `false` | | |
| 11 | 11 | | `true` | `false` | `false` | | |
| 12 | 12 | | `true` | `true` | `true` | | |
| 13 | 13 | ||
| 14 | 14 | ## Bitwise operation | |
| 15 | 15 | ||
| 16 | 16 | FPC also defines a bitwise `and`. Taking two ordinal operands logical `and` is calculated bit by bit: | |
| 17 | 17 | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 18 | + | ``` | |
| 19 | + | 1010'1100 | |
| 20 | + | and 0011'0100 | |
| 21 | + | ―――――――――――― | |
| 22 | + | 0010'0100 | |
| 23 | + | ``` | |
| 22 | 24 | ||
| 23 | 25 | ## comparative remarks | |
| 24 | 26 | ||
| 25 | 27 | Depending on the compiler's specific implementation of the data type [[Set|set]], the [[Asterisk|intersection of sets]] virtually does the same as the bitwise `and`. | |
| 26 | 28 | ||
| 27 | 29 | ## see also | |
| 28 | 30 | ||
| 29 | 31 | - [[Or|or]] | |
| 30 | 32 | ||
| 31 | 33 | --- | |
| 32 | 34 | *From the Free Pascal wiki, page "And", as it stood on 2022-11-27 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
