Integer Literals

Integer literals are constant data elements that have no fractional parts or exponents. They always begin with a numeral (0-9). You can specify integer constants in decimal, octal, hexadecimal, or binary form. You can specify signed or unsigned types and long or short types. If there is no specified suffix, the default type is Long.

ATEasy has the following integer literals:
 

Type

Description

Recommended prefix for variables

Suffix

Size in bytes (sizeof)

Value range

Examples

Char

signed integer

c

 

1

–128 to 127

'x'

Byte

unsigned integer

uc

uc

1

0 to 255

10uc

Short

signed integer

n

n

2

–32,768 to 32,767

145n

Word

unsigned integer

w

w

2

0 to 65,535

23w

WChar

signed integer

wc

L

2

-32,768 to 32,767

'a'L 

Long

signed integer

l (letter 'L")

l

4

–2,147,483,648 to 2,147,483,647

123, 123l (suffix of lower case letter 'L')

DLong

8 byte signed integer

ld

ld

8

-9223372036854775808 to 9223372036854775807

256ld

DWord

unsigned integer

dw

ul

4

0 to 4,294,967,295

123ul or 0xFA316

DDWord

8 byte unsigned integer

ddw

uld

8

0 to 18446744073709551615

256uld

Syntax

literal [optional suffix]

The syntax has the following parts:
 

Name

Type

Description

literal

literal constant

A decimal, hexadecimal, binary, or char constant.

suffix

suffix

A character string specifying the type of literal constant. See table above.

Where

literal can be one of the following:

 

Name

Components

Description

decimal-constant

The digits 0-9: 0 1 2 3 4 5 6 7 8 9

The first digit may be zero.

hexadecimal-constant

0x plus one or more hexadecimal digits.

The hexadecimal digit may be one of the following:

0 1 2 3 4 5 6 7 8 9

a b c d e f

A B C D E F

binary-constant

0b plus one or more binary digits.

The binary digit may be one of the following:

0 1

char-constant

For ASCII constants, the alphabetic characters A through Z (either upper or lower case). For escape sequences, any alphabetic or printable keyboard key.

Used to ensure a given char constant is used literally. For example,

Print '\''

will enter a single quotation mark into the log file.

Default Types for Constants

If a suffix is not provided, the following table lists the default types:
 

Constant

Default type

'x'

Char

123

Long

4.56

Double

0xABC

DWord

Comments

Since any numeric type is automatically converted to any other numeric type as needed, there are few situations where suffixes are really required. In ATEasy the constants used or initial values do not have to have the same type as the variable being initialized. The only requirement is that the assignment statement variable constant is legal.

For the array and structure initial values, it must be legal to assign each value provided with the corresponding array element or struct field. For example, given

adX ! Double [3]

then {'A', -3, 0xABCD} is a legal initial value.

Examples

Decimal literal:

To specify a decimal literal, begin the specification with a numeral. For example:

i = 157 ! Decimal literal

Hexadecimal literal:

To specify a hexadecimal literal, begin the specification with 0x, followed by a sequence of numerals in the range 0 through 9 and a (or A) through f (or F). Hexadecimal numerals a (or A) through f (or F) represent values in the range 10 through 15. For example:

i = 0x3fff ! Hexadecimal literal

j = 0X3FFF ! Equal to i

Binary literal:

To specify a binary literal, begin the specification with 0b, followed by a sequence of numerals in the range 0 through 1. For example:

i = 0b1001001 ! Binary literal

j = 0x49 ! Equal to i

k = 73 ! Equal to i

Unsigned types:

To specify an unsigned type, use the u suffix. To specify a long type, use the l suffix. For example:

uVal = 328u ! Unsigned value

lVal = 0x7FFFFFl ! Long value specified as hex literal

ulVal = 0776745ul ! Unsigned long value

ASCII characters or escape sequences:

To specify a single ASCII character or Escape Sequence, surround the constant by single quotation marks ('):

'a', '\n', '\x0A'

See Also

Escape Sequences, Floating Point Literals