You get an overview of how the text interpreter converts its numeric input in Literals in source code. This section describes some related words.

By default, the number base used for integer number conversion is
given by the contents of the variable `base`

. Note that a lot of
confusion can result from unexpected values of `base`

. If you
change `base`

anywhere, make sure to save the old value and
restore it afterwards; better yet, use `base-execute`

, which does
this for you. In general I recommend keeping `base`

decimal, and
using the prefixes described in Literals in source code for the
popular non-decimal bases.

`base-execute`

(i*x xt u – j*x) gforth-0.7 “base-execute”

execute *xt* with the content of `BASE`

being *u*, and
restoring the original `BASE`

afterwards.

`base`

(– a-addr) core “base”

`User`

variable – *a-addr* is the address of a cell that
stores the number base used by default for number conversion during
input and output. Don’t store to `base`

, use
`base-execute`

instead.

`hex`

(–) core-ext “hex”

Set `base`

to &16 (hexadecimal). Don’t use `hex`

,
use `base-execute`

instead.

`decimal`

(–) core “decimal”

Set `base`

to &10 (decimal). Don’t use `decimal`

, use
`base-execute`

instead.

`dpl`

(– a-addr) gforth-0.2 “Decimal-PLace”

`User`

variable – *a-addr* is the address of a cell that stores the
position of the decimal point in the most recent numeric conversion.
Initialised to -1. After the conversion of a number containing no
decimal point, `dpl`

is -1. After the conversion of `2.`

it holds
0. After the conversion of 234123.9 it contains 1, and so forth.

Number conversion has a number of traps for the unwary:

- You cannot determine the current number base using the code sequence
`base @ .`

– the number base is always 10 in the current number base. Instead, use something like`base @ dec.`

- There is a word
`bin`

but it does*not*set the number base! (see General files). - Standard Forth requires the
`.`

of a double-precision number to be the final character in the string. Gforth allows the`.`

to be anywhere. - The number conversion process does not check for overflow.

You can read numbers into your programs with the words described in Line input and conversion.