5.4.2 Writing an integer in an arbitrary base
The convert or
convertir
command does various kinds of conversions depending on the option
given as the second argument (see Section 10.1.10).
One thing that convert can do is to
convert integers to arbitrary bases and back to the default base, both
with the option base.
Conversion from base 10.
An integer can be converted into a list of digits in base b by
using the convert command.
-
convert takes three
arguments:
-
n, an integer.
- base, the symbol verbatim.
- b, a positive integer, the value of the base.
- convert(n,base,b) returns the list of
digits of the integer n when written in base b. The
list of digits will start with the 1s term, then the
bs term, the b2 term, etc.
Examples
To verify, input 0173 (see Section 5.4.1) or
horner(revlist([3,7,1]),8) (see Section 11.1.13 and
Section 6.3.14) or convert([3,7,1],base,8) which all return 123.
The base used for convert can be any integer greater than 1.
For example, input:
Conversion from an arbitrary base b.
A number written in base b can be converted into a base 10 integer
by using the convert command.
-
convert takes three arguments:
-
L, a list of integers representing the digits of the
integer in base b, assumed to go in order of increasing
significance.
- base, the symbol verbatim.
- b, a positive integer, the value of the base.
- convert(L,base,b) returns the integer which, in
base b, has the digits given in L.
Examples