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 |
DECIMAL | 0 to 9999 | 2 |
STRING | N/A | 1-97 |
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
.
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:
.
) will be recognized as FLOAT. For example, the number 1.0
is a FLOAT. You must use a decimal point in a FLOAT, even if its fractional part is zero. Without the decimal point the compiler will treat the number as an integral number and the program might be spending precious runtime converting it back to FLOAT.d
will be recognized as DECIMAL. For example, 9999d
is a valid DECIMAL.Note
You can use scientific notation, e.g 1.453E-12
when writing FLOAT literals.
Numeric literals can be written in decimal, hexadecimal and binary form.
$
sign is recognized as hexadecimal, for example: $03FF
.%
sign is recognized as binary, for example: %01110101
.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 are fixed-length series of PETSCII characters. You can read more about strings on the Strings page.