You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

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:

  • An integer between 0 and 255 will be treated as a byte
  • An integer between -32768 and 65535 will be treated as an integer
  • A number that features a decimal point (.) and is between -1.70141183E38 and 1.70141183E38 will be treated as a float. Normal and scientific notation are both accepted.
  • In any other cases the error “Number out of range” will be displayed and compilation will fail

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