NOT
y = NOT {a|expr}
Logical operator to invert variable or expression result. Equivalent
syntax to y = !a
. NOT returns true if variable or
expression result is false or zero. Otherwise it returns false.
For bitwise NOT use the ~ operator.
Example 1:
print not true ' Output: 0
print not 100 ' Output: 0
print not false ' Output: 1
print not 0 ' Output: 1
Example 2: NOT in an if statement
false ' Replace with true
IsRunning = if(NOT IsRunning) then print "Program is not running"
0 ' Replace i.e. 10
a = if(NOT a) then print "Value is zero"
Example 3: Bitwise NOT using ~
The NOT-operation performs a bitwise inversion on all bits of a number. This leads to the following (maybe unexpected) result:
print bin(~0b1001) ' Output: 11111111111111111111111111110110
Example 4: Operate bitwise NOT only on last n bits
If you want to operate NOT only on the last n
bits of
the numbers, you can use the following code:
4
n = 0b1010
a =
print bin((~a) BAND ((1 lshift n ) - 1))
' Output 101
Code samples using NOT
001 3 ways to print hello 5 times.bas
002 numeric variables.bas
003 conditional branching.bas
004 loops.bas
005 challenge.bas
006 arrays+.bas
2048.bas
2048.bas
3d block lettes.bas
3d_palmx.bas
3d_torus.bas
3dtorus.bas
4tune.bas
7gables.bas
Another center finder.bas
another look at trig functions.bas
ascii 3d.bas
Balleta 2-11-15.bas
BAS_1968.bas
BAS_NOW.bas
base64.bas
betrayal: crows ii.bas
bezier_pen.bas
blackbox.bas
Blackbox.bas
blackjack.bas
BlackJack.bas
block.bas
blushing snowflakes.bas
Language
AND
AS
BAND
BG
BOR
BYREF
CALL
CASE
CATCH
CONST
DECLARE
DEF
DO
ELIF
ELSE
ELSEIF
END
END TRY
ENDIF
EQV
EXIT
FALSE
FI
FOR
FUNC
GOSUB
GOTO
IF
IFF
IMP
IN
LABEL
LET
LIKE
LOCAL
LSHIFT
MDL
MOD
NAND
NEXT
NOR
NOT
ON
OR
REM
REPEAT
RETURN
RSHIFT
SELECT
STEP
STOP
SUB
THEN
THROW
TO
TRUE
TRY
UNTIL
USE
USG
USING
WEND
WHILE
XNOR
XOR
If there is insufficient information on this page and you wish learn more about NOT,
please send an email to smallbasic@gmail.com. You can help to improve information about
NOT by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.