Home > CBM > BASIC > Keywords > Not
180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Usr, Val, Verify, Vol, Wait, While, Width, Window, Xor

KeywordAbbreviationToken (hex)Version(s)Classification
NOTN{Shift+O}A81.0 to 7.0Operator (5)

 Syntax 
NOT expression
 
ParametersTypeLegal Value(s)Default ValueNote(s)
expressionFloat or Integer
-32768 to +32767
 
ReturnsTypeValue(s)Note(s)
resultInteger
-32768 to +32767
Will be -1 or 0 if expression is 0 or -1
 
 Purpose 
Evaluate a bit-wise boolean operation.

 
 Remarks 
The NOT operator is often used in logical expressions, and may be considered a logical operator.  However, this is not really the case and can have nasty consequences if you're not aware of how it actually functions.  First, if the expression is a string, a TYPE MISMATCH ERROR is generated.  Next, if the expression is floating-point then it is converted to an integer; if the result is not a legal value (see above) then ILLEGAL QUANTITY ERROR is generated.  Finally, each of the 16 bits in the integer is complemented to produce the result.
 
If the expression is 0 or -1 then the result will be -1 or 0, which is completely logical.  BASIC operators which return a boolean result always return -1 for true or 0 for false so this works well most of the time.  However, using NOT with other non-zero values (besides -1) will produce another non-zero value.  This is not logical, which is why this is more properly called a bit-wise boolean operation.  Examples are provided below, but to really understand them, you need to know how to convert a decimal number into binary (and back again).  I won't try to explain that here; you may find this web page helpful for experimenting, or use a calculator.
 
Also important to note is that logical and bit-wise negation (discussed on this page) are different (though similar) to comparison for inequality; see the less and more operators (< and >).
 
The NOT operator has a very low operator priority (5), which is less than all arithmetic and relational operators.  Its priority, however, is greater than the AND and OR bit-wise operators.  Of course the user may invoke parentheses to change the order of evaluation.
 
Boolean/Logical operators (like NOTl) are often used with IF, DO, and LOOP. 
 
Some "logical" examples:
PRINT NOT "A"

?TYPE MISMATCH ERROR
READY.
A=1 : B=2

READY.
PRINT NOT A>B
-1

READY.
PRINT NOT A<B
 0
READY.
 
Some examples about operator priority:
A=1 : B=2 : PRINT NOT A<B AND A>B
 0
 
READY.
PRINT NOT (A<B AND A>B)
-1
READY.
 
Some examples demonstrating bit-wise complement:
A=1      : REM binary 0000 0000 0000 0001

READY.
PRINT NOT A
-2       : REM binary 1111 1111 1111 1110 -- not logical!

READY.
PRINT (NOT A) AND A <>0 : REM the () are unneccessary
-2       : REM also not logical, because of NOT A

READY.
 
 Compare With 
<, >, -, XOR
 
 Contrast With 
+, =
 
 See Also 

© H2Obsession, 2014