Writing an integer in an arbitrary base b: convert

### 6.4.2 Writing an integer in an arbitrary base b: convert

The convert command does various kinds of conversions depending on the option given as the second argument (see Section 6.23.26). convertir is a synonym for convert.

One thing that convert can do is convert integers to arbitrary bases and back to the default base, both with the option base.

To convert an integer into the list of its “digits” in base b:

- 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.

Example.
Input:

convert(123,base,8)

Output:

⎡ ⎣ | 3,7,1 | ⎤ ⎦

To check the answer, input 0173 (see Section 6.4.1) or horner(revlist([3,7,1]),8) (see Section 6.27.19 and Section 6.40.15) or convert([3,7,1],base,8). The result will be 123.

The base used for convert can be any integer greater than 1.

Example.
Input:

convert(142,base,12)

Output:

⎡ ⎣ | 10,11 | ⎤ ⎦

To convert the its “digits” in base b into a base 10 integer:

- 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.

- Input:
  convert([3,7,1],base,8)
  Output:

  123

- Input:
  convert([10,11],base,12)
  Output:

  142