GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Download
  • News
  • Community
  • Resources
  • Language Reference
  • SmallBASIC Manual

This view

  • Original page
  • New address

GeezerVison is showing smallbasic.github.io — SmallBASIC | NOT

Edit History

NOT

y = NOT {a|expr}

Home > Reference > Language

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

IsRunning = false                ' Replace with true
if(NOT IsRunning) then print "Program is not running"
a = 0             ' Replace i.e. 10
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:

n = 4
a = 0b1010

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   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   bolmo.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  
This page was last edited on Thu, 8 Jun 2023 15:04:46 +0200 | Markdown processed with pandoc 3.1.12.1
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.