Difference between revisions of "Not"

From Free Pascal wiki
Jump to navigationJump to search
(substitute legacy syntaxhighlight syntax; grammar; typography; more links; clarification)
(add footer, cat)
 
Line 39: Line 39:
 
For example, <syntaxhighlight lang="delphi" inline>boolean(not %1)</syntaxhighlight> will evaluate as <syntaxhighlight lang="pascal" inline>true</syntaxhighlight>, but only <syntaxhighlight lang="delphi" inline>boolean(not high(nativeUInt))</syntaxhighlight> will evaluate to <syntaxhighlight lang="pascal" inline>false</syntaxhighlight>.
 
For example, <syntaxhighlight lang="delphi" inline>boolean(not %1)</syntaxhighlight> will evaluate as <syntaxhighlight lang="pascal" inline>true</syntaxhighlight>, but only <syntaxhighlight lang="delphi" inline>boolean(not high(nativeUInt))</syntaxhighlight> will evaluate to <syntaxhighlight lang="pascal" inline>false</syntaxhighlight>.
  
== See also ==
+
{{Logical operators}}
 +
* {{Doc|package=RTL|unit=system|identifier=.op-logicalnot-variant-ariant|text=<syntaxhighlight lang="pascal" inline>system.logicalNot</syntaxhighlight>}}
  
* {{Doc|package=RTL|unit=system|identifier=.op-logicalnot-variant-ariant|text=<syntaxhighlight lang="pascal" inline>system.logicalNot</syntaxhighlight>}}
+
[[Category:Operators]]

Latest revision as of 23:14, 16 October 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 represents 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 &#8965; A }[/math].

Note, that only not %0 will definitely result in a value interpretable as true. However, not every other 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.


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”