Syntax
value = not expr
Description
The not bitwise operator interprets expr as an integer, and returns another integer in whose internal bit pattern all the bits are flipped to their opposite state (i.e., all 1's are changed to 0; and all 0's are changed to 1). Coincidentally, because of the way that integers are stored in FutureBasic, the value returned by not expr equals: -(expr + 1)
.
testValue = 35
if testValue then beep // This produces a beep
if not testValue then beep // But so does this!
This program produces two beeps, because in the second if statement, "not testValue
" produces the value -36, which is still interpreted as "true" by the if statement.
Another common use for not is to help you set or reset individual bits in a bit pattern. For example:
pattern = pattern and not bit(7)
This sets bit 7 in pattern
to zero, and leaves all of pattern
's other bits alone.
Reminder
not is a bitwise operator, meaning it acts on bits like other FB bitwise operators such as and, or. Unless you're specifically intending to utilize bits (i.e. bit flipping, bit testing), it's highly likely your code needs a logical comparison resulting in either true or false. Several logical boolean operators are available such as &&, ||
See also
and; ! - logical 'not'; or; xor