DelphiBasics
Not
Keyword
Boolean Not or bitwise not of one arguments
1 keyword Not(Not Boolean expression
2 Not Integer expression
Description
The Not keyword is used in two different ways:
 
1. To perform a logical or boolean 'Not' of a logical value.If True, the value becomes False. If False, the value becomes True.
 
2. To perform a mathematical 'Not' of an integer in a bitwise fashion. The result is a bitwise 'Not' of the number - every bit value is reversed - 0 to 1 and 1 to 0.
Notes
If the boolean expression is calculated (as opposed to being a Boolean variable), then brackets are required to isolate it.
Related commands
AndBoolean and or bitwise and of two arguments
BooleanAllows just True and False values
IfStarts a conditional expression to determine what to do next
OrBoolean or or bitwise or of two arguments
XorBoolean Xor or bitwise Xor of two arguments
 Download this web site as a Windows program.




 
Example code : Illustrate both types of Not usage
var
  num1, num2 : Word;

begin
  num1   := $2C;    // Binary value : 0000 0000 0010 1100
                    // Not'ed value : 1111 1111 1101 0011 = $FFD3

  // And used to return a Boolean value
  if Not (num1 > 0)
  then ShowMessage('num1 <= 0')
  else ShowMessage('num1 > 0');

  // And used to perform a mathematical NOT operation
  num2 := Not num1;

  // Display the result
  ShowMessage('Not $2C = $'+IntToHex(num2,2));
end;
Show full unit code
  num1 > 0
  Not $2C = $FFD3
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page