Previous Up Next

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.

Examples

convert(123,base,8)
     

3,7,1
          

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:

convert(142,base,12)
     

10,11
          
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.

Examples

convert([3,7,1],base,8)
     
123           
convert([10,11],base,12)
     
142           

Previous Up Next