Difference between revisions of "Not"

From Free Pascal wiki
Jump to navigationJump to search
(review)
(→‎bitwise operation: correct statement)
Line 29: Line 29:
 
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 \barwedge (111…111)_2</math>.
+
On NAND-gate-based architectures the <syntaxhighlight lang="asm" enclose="none">not</syntaxhighlight> instruction can be calculated by the expression <math>A \barwedge 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>.

Revision as of 16:01, 7 November 2018

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
truth table for logical negation

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 \barwedge 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.

see also