-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase-n.py
More file actions
31 lines (23 loc) · 695 Bytes
/
Copy pathbase-n.py
File metadata and controls
31 lines (23 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# BASE N
import math
# http://villemin.gerard.free.fr/Wwwgvmm/Numerati/ConBin.htm
# Il existe 10 sortes de personnes
# ceux qui connaissent le binaire et ceux qui ne le connaissent pas.
nombre = 13
print("Nombre ", nombre)
base = 2
print("Base ", base)
poidMax = int(nombre/base)
print("PoidMax ", poidMax)
def toBase2(nombre):
reste = nombre
newNombre = ""
for poid in reversed( range(poidMax+1) ):
if (reste - math.pow(base, poid))>=0 :
reste -= math.pow(base, poid)
newNombre += str(1)
else:
newNombre += str(0)
return newNombre
print("Nombre en base ", base, ": ", toBase2(nombre) )
### EN COURS / PAS TERMINE