transforms a number from one base into another base
n = change_base(m,b1,b2)
character string or vector of positive integers
positive integer
positive integer
character string or vector of positive integers
n=change_base(m,b1,b2)
transforms the number
m
written in base b1
into a number
n
written in base b2
. There are two ways to reprsent the number
m
in base
b1
which are described below.
For the bases b1
and b2
equal to 2,3,4,5,6,7,8,9 ou 16 on may represent the number
m
in the form of a character string in which each character represents a digit.
For example 210 in base 3 is represented by the character string "210".
The result
n
is also given in the form of a character string.
If the base b1 is equal to 16, one may represent m
using the usual letters A, B, C,
D, E et F to designate the numbers 10, 11, 12, 13, 14 et 15. If the
base b2 is equal to 16, n
would also contain these letters in return.
In any base, one represents the number
m
in the form of a vector of positive integers.
For example 210 in base 3 would be represented by the vector [2,1,0]. The result
n
would also be given in the form of a vector of positive integers.
This enables using bases larger than 9 and different from 16. For example the number
3*12^2+11*12+10 would be represented by [3,11,10] in base 12.