A number may be expressed in binary form in SmileBasic by using the prefix
&B. For a numeric literal,
&b is converted to
&B, so for example
PRINT &b100 gives
PRINT VAL("&b100") gives
Syntax error (VAL). Another difference between the way
&B is handled in literals and in
VAL is that
VAL does not require any digits to follow:
PRINT &B makes a
Syntax error, but
PRINT VAL("&B") gives
If more than 20 bits follow the prefix in a literal, the system will generate a
Syntax error, even if the first bits are
0 and the value is within SmileBasic's range. If more than 20 bits follow the prefix in a string passed to
VAL, the system instead generates an
Overflow (VAL) error, again even if the value is within SmileBasic's range. The values
&B11111111111111111111 give negative numbers in the standard 2s complement sense, and
&B10000000000000000000 in particular is a value which exposes some bugs in SmileBasic.
In some instances, it is not necessary to put a space between the end of the literal and the following operator, e.g.
PRINT &B1+&B1 will give
2 as expected, but in others, it is necessary, e.g.
PRINT &B1OR&B1 gives the confusing result
101, and the assignment
V=&B1OR&B1 generates a
Syntax Error. The commands
PRINT &B1 OR&B1 and
V=&B1 OR&B1 will give the expected results.
The prefix for hexadecimal values is