Table of Contents

Numeric literals

There are several ways you can express a number in XC=BASIC and there are a few rules you have to keep in mind.

Data types

Currently three numeric types are supported: byte, integer and float. The compiler will follow these rules when parsing numbers:

A note on integers

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.

A note on floats

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

Numeral systems

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