There are several ways you can express a number in XC=BASIC and there are a few rules you have to keep in mind.
Currently three numeric types are supported: byte, integer and float. The compiler will follow these rules when parsing numbers:
.
) and is between -1.70141183E38 and 1.70141183E38 will be treated as a float. Normal and scientific notation are both accepted.
While integers are signed shorts in XC=BASIC, some of the commands (e.g. PEEK
and POKE
) treat them as unsigned. For this reason it is allowed to use numbers between 32767 and 65535, but they'll be treated as negative numbers by most of the commands. For example
print 65535
will output -1, because PRINT
treats integers as signed 2-byte numbers.
While any integer numbers are valid floats as well, you must distinguish them because the compiler is not smart enough to do so. The way you can express floats is to always write a decimal point, for example:
let a% = 1.0
You can express byte and integer types in decimal, hexadecimal or binary numeral systems. The $
prefix indicates a hexadecimal, while the %
prefix indicates a binary number. Examples:
let dnum = 10000 let hexa = $d020 let binary = %10010011