San Vu Ngoc - IRMAR


Écriture en base $b$

Quel est le nombre qui s'écrit "5614" en base 7 ?

In [1]:
int("5615",7)
Out[1]:
2021
In [2]:
(((5)  *7 + 6) *7 +  1 ) *7  + 5
Out[2]:
2021
In [3]:
bin(2021)
Out[3]:
'0b11111100101'
In [4]:
hex(2021)
Out[4]:
'0x7e5'

Exercice: Algorithme de Horner

étant donnés la base $b$ et les coefficients $c_0$, ... , $c_k$, calculer l'entier correspondant, soit $$ n = c_k b^k + c_{k-1}b^{k-1} + \cdots + c_1 b + c_0 $$ sans calculer les puissances $b^j$.

In [5]:
oct(2021)
Out[5]:
'0o3745'
In [6]:
int("3745",8)
Out[6]:
2021
In [ ]: