Petit Computer Wiki
Register
Advertisement

!0 evaluates to 1. For any value other than 0, !value evaluates to 0. The code !value is therefore equivalent to (value==0), or perhaps more relevant, (value==FALSE). In this sense, ! is the logical NOT operator, which is different from the bitwise NOT operator because the makers of SmileBasic decided to use the value 1 to represent the boolean value 'true', instead of -1 like just about any other programming language out there.

This operator is in the unary precedence group, which is the highest. This means all unary operators are evaluated before any others, e.g. the bitwise operators, so !A AND B is evaluated as (!A) AND B. Since all unary operators are prefixes to their operands, they are right-associative, i.e. the rightmost ones are evaluated first.

Advertisement