wfroth reference : Integer Numeric I/O

 

This chapter presents a complete reference on wfroth.

Last update:

3-January-1999

State (estimation)

100%


This chapter includes the following sections:


Generalities

Integers have a precision of 32-bits (except for */ and */MOD). All conversions, from ascii to binary, or binary to ascii, use a variable, BASE, which contains the base for integer numeric I/O.

 

Glossary

BASE

( --- )

areg = &base

This variable contains the base used by the integer conversion routines words. Base can be from base 2 (binary) to base 36. From base 11, digits use letters (A-Z), lower or upper case. When starting, BASE is set by default to base 10 (decimal base).

 

DECIMAL

( --- )

: decimal base 10 ! ;

HEX

( --- )

: decimal base 16 ! ;

BINARY

( --- )

: decimal base 2 ! ;

OCTAL

( --- )

: decimal base 8 ! ;

Selects the given base.

 

.

( n --- )

This word pops the integer from top stack, then prints it on screen (starting from current position). The conversion is made using the value of BASE variable. The integer is interpreted as signed. There is no space printed before and after the number.

 

.L

( n1 n2 --- )

This word pops the integer n1 from top stack, then prints it on screen (starting from current position), left-justified in a field size of length n2. The conversion is made using the value of BASE variable. The integer is interpreted as signed.

 

.R

( n1 n2 --- )

This word pops the integer n1 from top stack, then prints it on screen (starting from current position), right-justified in a field size of length n2. The conversion is made using the value of BASE variable. The integer is interpreted as signed.

 

U.

( u --- )

This word pops the integer from top stack, then prints it on screen (starting from current position). The conversion is made using the value of BASE variable. The integer is interpreted as unsigned. There is no space printed before and after the number.

 

H.

( u --- )

This word pops the integer from top stack, then prints it on screen (starting from current position). The conversion is made always in hexadecimal, whatever the current value of BASE variable. The integer is interpreted as unsigned. There is no space printed before and after the number.

 

<#

( n --- n )

This word is used to begin the process of binary to ascii conversion. This word initialize the variable hld, to point to internal output buffer PAD.

 

#

( n1 --- n2 )

This word can only be used between <# and #>. The purpose of # is to convert the next digit of the number being converted: n1 is divided by the current base (see variable BASE), then the remainder is used as the next digit in the pictured output string, and the quotient is stored on stack. If you get zero as quotient value, that means that all digits of the number are converted. # must be used only if the number to convert is interpreted as a signed integer.

 

U#

( u1 --- u2 )

This word can only be used between <# and #>. The purpose of # is to convert the next digit of the number being converted: u1 is divided by the current base (see variable BASE), then the remainder is used as the next digit in the pictured output string, and the quotient is stored on stack. If you get zero as quotient value, that means that all digits of the number are converted. # must be used only if the number to convert is interpreted as an unsigned integer.

 

HOLD

( c --- )

This word can only be used between <# and #>. HOLD pops the character from top stack, then inserst it at the current location into the pictured output string (maintained into hld).

 

SIGN

( n1 --- n1 )

SIGN insert the minus sign '-' if the initial number to convert (see <#) was negative,else nothing occurs. SIGN is normally called in last, when all digits (from right to left) are convered and stored into the pictured output string.

 

#S

( n --- 0 )

This word converts all digits of the signed number n.

 

U#S

( u --- 0 )

This word converts all digits of the unsigned number n.

 

#>

( n --- )

areg = *hld

This word ends the process of binary to ascii conversion. The number on top stack is usually 0, that means that all digits of initial number were converted, and each digit has been stored into the pictured output string. The word #> gives you the address of an internal buffer (PAD), which contains the string ready to be printed. Usually, you will print the string, using TYPE (preceded by the word A>).

 

<#S>

( n --- sz )

This word does the complete process of binary to ascii conversion. The number (from top stack) is converted using the current value for base integer I/O. As the word #>, the word <#S> gives you the address of internal buffer, which contains the string ready to be printed. Usually, you will print the string, using TYPE.

 

NUMBER

( sz --- n f )

This word try to convert a given string to an integer, according to the current base for integer numeric I/O (see variable BASE). If conversion fails, a false flag (tf = FALSE = 0) is let on top stack. If conversion succeeds, the value n and a true flag (tf = TRUE = 1) is let on stack. Heading and trailing spaces into string to convert are ignored.