To push an integer number on the data stack, you write the number in
source code, e.g., 123. You can prefix the digits with
- to indicate a negative number, e.g. -123. This works
both inside colon definitions and outside. The number is interpreted
according to the value in base (see Number Conversion).
The digits are 0 to 9 and a (decimal 10) to
z (decimal 35), but only digits smaller than base @ are
recognized. The conversion is case-insensitive, so A and
a are the same digit.
You can make the base explicit for the number by using a prefix:
# – decimal
% – binary
$ – hexadecimal
& – decimal (non-standard)
0x – hexadecimal, if base<33 (non-standard).
For combinations including base-prefix and sign, the standard order is
to have the base-prefix first (e.g., #-123); Gforth supports
both orders.
You can put a decimal point . at the end of a number (or,
non-standardly, anywhere else except before a prefix) to get a
double-cell integer (e.g., #-123. or #-.123 (the same
number)). If users experienced in another programming language see or
write such a number without base prefix (e.g., -123.), they may
expect that the number represents a floating-point value. To clear up
the confusion early, Gforth warns of such usage; to avoid the
warnings, the best approach is to always write double numbers with a
base prefix (e.g., #-123.)
Here are some examples, with the equivalent decimal number shown after in braces:
$-41 (-65), %1001101 (205), %1001.0001 (145, a
double-precision number), #905 (905), $abc (2478),
$ABC (2478).
You can get the numeric value of a (character) code point by
surrounding the character with ' (e.g., 'a'). The
trailing ' is required by the standard, but you can leave it
away in Gforth. Note that this also works for non-ASCII characters.
For many uses, it is more useful to have the character as a string
rather than as a cell; see below for the string syntax.