Jump to content

Futurebasic/Language/Reference/not

From Wikibooks, open books for an open world

Syntax

[edit | edit source]
value = NOT expr

Description

[edit | edit source]

The NOT 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 FB, the value returned by NOT expr equals: -(expr + 1).

One common use for NOT is to reverse the sense of an expression whose value equals _zTrue (-1) or _false (0). Note that (NOT_zTrue) returns _false, and (NOT _false) returns _zTrue. You must be careful when using NOT with "true" values other than -1. For example:

testValue = 35
IF testValue <b>THEN BEEP</b> 'This produces a beep<br>
</code><code><b>IF NOT</b> testValue <b>THEN BEEP</b> '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& <b>AND NOT BIT</b>(7)

This sets bit 7 in pattern& to zero, and leaves all of pattern&'s other bits alone.

See Also

[edit | edit source]

AND; OR; XOR