Converts integers between base 10 and other bases (R.W. Payne).
|Controls printed output (
||Whether to convert
||Base to which to convert number; default 2|
||Number in base 10|
||Digits of the
||Sign of the
NCONVERT can be used to convert an integer between the standard base 10 and another base, specified by the
BASE option (default 2 i.e. binary). The number in base 10 is specified by the
NUMBER parameter. In the other base it is represented in a pointer, specified by the
DIGITS parameter, containing an integer for each of the digits required to represent it in that base. The
SIGN parameter contains a scalar with the value +1 or -1 according to whether the number is positive or negative.
For example, the number 29 in base 10 would be represented in base 2 by a pointer containing five scalars with the values 1, 1, 1, 0 and 1. This results from the fact that
29 = 16 + 8 + 4 + 1
So there are 5 digits corresponding to the multipliers of 24, 23, 22, 21 and 20.
number, which prints the number in the two bases. By default this is printed, but you can suppress that by setting
METHOD option controls the direction of the conversion: the default,
tobase, converts from base 10 to the other base; conversion in the other direction is requested by the alternative setting,
The conversion is done by standard arithmetic using, for example, the
Commands for: Calculations and manipulation.
CAPTION 'NCONVERT example'; STYLE=meta NCONVERT 36176 & -36176; DIGITS=D; SIGN=S PRINT D; FIELD=3; DECIMALS=1 NCONVERT [METHOD=FROMBASE] *; DIGITS=D; SIGN=S & *; DIGITS=D; SIGN=1 NCONVERT [BASE=3] 90 & -90; DIGITS=D; SIGN=S PRINT D; FIELD=3; DECIMALS=1 NCONVERT [BASE=3; METHOD=FROMBASE] *; DIGITS=D; SIGN=S & *; DIGITS=D; SIGN=1