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 Base and integer decimal point).
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)).
By default (.-is-dcell? pushes true), prefixless numbers with
a decimal point (e.g., -123.) are also recognized as
double-cell integers. This is confusing to users experienced in other
programming language. 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.). This
also works in the setting 0 to .-is-dcell?.
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.