San Vu Ngoc - IRMAR


Écriture en base $b$¶

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

In [1]:
int("5620",7)
Out[1]:
2023
In [2]:
(((5)  *7 + 6) *7 +  2 ) *7  + 0
Out[2]:
2023
In [3]:
bin(2023)
Out[3]:
'0b11111100111'
In [4]:
hex(2023)
Out[4]:
'0x7e7'

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(2023)
Out[5]:
'0o3747'
In [6]:
int("3747", 8)
Out[6]:
2023
In [7]:
int("31043",5)
Out[7]:
2023