Table of Contents

Data Types

XC=BASIC offers 7 built-in data types (also called primitive types):

Type Numeric range Size in bytes
BYTE 0 to 255 1
INT -32,768 to 32,767 2
WORD 0 to 65,535 2
LONG -8,388,608 to 8,388,607 3
FLOAT ±2.93874⨉10-39 to ±1.69477⨉1038 4
DECIMAL0 to 9999 2
STRING N/A 1-97

Numeric types

Warning

Floating point variables have great flexibility because they can store very large and very small numbers, including a decimal fraction. However, they are manipulated much more slowly than the other types, and therefore should be used with caution and only when necessary.

Warning

DECIMAL has strict limitations. It only supports addition and subtraction and can not be converted to or from any other types.

Note

When displaying decimals, all the leading zeroes will be displayed. For example the number 99 will be displayed as 0099.

Numeric literals

When compiling the program, the compiler must assign a type to all numbers it encounters. The compiler will identify the type of a number through the following rules:

Note

You can use scientific notation, e.g 1.453E-12 when writing FLOAT literals.

Numeral systems

Numeric literals can be written in decimal, hexadecimal and binary form.

Warning

Binary and hexadecimal numbers are always assumed unsigned. For example the number $FFFF will be treated as 65535 (WORD) rather than -1 (INT).

Strings

Strings are fixed-length series of PETSCII characters. You can read more about strings on the Strings page.