Difference between revisions of "Not"
(→bitwise operation: clarification) |
m (Fiixed bar wedge character entity) |
||
Line 1: | Line 1: | ||
{{not}} | {{not}} | ||
+ | |||
The unary operator <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> negates a Boolean value. | The unary operator <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> negates a Boolean value. | ||
[[FPC]] also knows the bitwise <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> when supplied with an ordinal type. | [[FPC]] also knows the bitwise <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> when supplied with an ordinal type. | ||
+ | |||
<syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> is a reserved word. | <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> is a reserved word. | ||
== Boolean operation == | == Boolean operation == | ||
+ | |||
The operator <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> represent the logical negation <math>\neg A</math>. | The operator <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> represent the logical negation <math>\neg A</math>. | ||
In electrical engineering one might write <math>-A</math> or <math>\overline{A}</math> instead, however the unary [[Minus|minus sign]] has a different meaning in programming. | In electrical engineering one might write <math>-A</math> or <math>\overline{A}</math> instead, however the unary [[Minus|minus sign]] has a different meaning in programming. | ||
Line 17: | Line 20: | ||
| <syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight> | | <syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight> | ||
| style="background: #eeeeee" | <syntaxhighlight lang="pascal" enclose="none">false</syntaxhighlight> | | style="background: #eeeeee" | <syntaxhighlight lang="pascal" enclose="none">false</syntaxhighlight> | ||
− | |+ | + | |+ Truth table for logical negation |
|} | |} | ||
<syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> has the highest precedence among logical operators. | <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> has the highest precedence among logical operators. | ||
− | == | + | == Bitwise operation == |
+ | |||
The bitwise <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> flips every bit in an ordinal type. | The bitwise <syntaxhighlight lang="pascal" enclose="none">not</syntaxhighlight> flips every bit in an ordinal type. | ||
not 1100'1010 | not 1100'1010 | ||
Line 29: | Line 33: | ||
It effectively calculates the one's complement. | It effectively calculates the one's complement. | ||
On virtually all platforms it is implemented by the <syntaxhighlight lang="asm" enclose="none">not</syntaxhighlight> instruction. | On virtually all platforms it is implemented by the <syntaxhighlight lang="asm" enclose="none">not</syntaxhighlight> instruction. | ||
− | On NAND-gate-based architectures the <syntaxhighlight lang="asm" enclose="none">not</syntaxhighlight> instruction can be calculated by the expression <math>A | + | On NAND-gate-based architectures the <syntaxhighlight lang="asm" enclose="none">not</syntaxhighlight> instruction can be calculated by the expression <math>A ⌅ A</math>. |
Note, that only <syntaxhighlight lang="pascal" enclose="none">not %0</syntaxhighlight> will definitely result in a value interpretable as <syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight>. | Note, that only <syntaxhighlight lang="pascal" enclose="none">not %0</syntaxhighlight> will definitely result in a value interpretable as <syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight>. | ||
Line 35: | Line 39: | ||
For example, <syntaxhighlight lang="delphi" enclose="none">boolean(not %1)</syntaxhighlight> will evaluate as <syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight>, but only <syntaxhighlight lang="delphi" enclose="none">boolean(not high(nativeUInt))</syntaxhighlight> will evaluate to <syntaxhighlight lang="pascal" enclose="none">false</syntaxhighlight>. | For example, <syntaxhighlight lang="delphi" enclose="none">boolean(not %1)</syntaxhighlight> will evaluate as <syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight>, but only <syntaxhighlight lang="delphi" enclose="none">boolean(not high(nativeUInt))</syntaxhighlight> will evaluate to <syntaxhighlight lang="pascal" enclose="none">false</syntaxhighlight>. | ||
− | == | + | == See also == |
+ | |||
* {{Doc|package=RTL|unit=system|identifier=.op-logicalnot-variant-ariant|text=<syntaxhighlight lang="pascal" enclose="none">system.logicalNot</syntaxhighlight>}} | * {{Doc|package=RTL|unit=system|identifier=.op-logicalnot-variant-ariant|text=<syntaxhighlight lang="pascal" enclose="none">system.logicalNot</syntaxhighlight>}} |
Revision as of 10:30, 21 February 2020
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
The unary operator not
negates a Boolean value.
FPC also knows the bitwise not
when supplied with an ordinal type.
not
is a reserved word.
Boolean operation
The operator not
represent the logical negation [math]\displaystyle{ \neg A }[/math].
In electrical engineering one might write [math]\displaystyle{ -A }[/math] or [math]\displaystyle{ \overline{A} }[/math] instead, however the unary minus sign has a different meaning in programming.
A
|
not A
|
---|---|
false
|
true
|
true
|
false
|
not
has the highest precedence among logical operators.
Bitwise operation
The bitwise not
flips every bit in an ordinal type.
not 1100'1010 ――――――――――――― 0011'0101
It effectively calculates the one's complement.
On virtually all platforms it is implemented by the not
instruction.
On NAND-gate-based architectures the not
instruction can be calculated by the expression [math]\displaystyle{ A ⌅ A }[/math].
Note, that only not %0
will definitely result in a value interpretable as true
.
However, not every not x
will result in a value interpretable as false
, since only 0
is considered as false
and every other value as true
.
For example, boolean(not %1)
will evaluate as true
, but only boolean(not high(nativeUInt))
will evaluate to false
.