← Retour au cours Entiers

Position pondérée

base b

N = Σ ci · b^i avec 0 ≤ ci < b.

Base 10
7307 = 7·10³ + 3·10² + 0·10¹ + 7·10⁰
Base 2
Chiffres {0, 1} = bits
MSB
Bit de poids fort
LSB
Bit de poids faible

Python

bin int

Fonctions intégrées pour manipuler les bases.

bin(13)
'0b1101'
int('1101', 2)
13
0b1101
Littéral binaire
0b1101 en décimal
8+4+0+1 = 13

💻 Exemples de code

Chiffres → nombre (base 10)

chiffres2nombre.py
def chiffres2nombre(liste_chiffres):
    nombre = 0
    for chiffre in liste_chiffres:
        nombre = nombre * 10 + chiffre
    return nombre

print(chiffres2nombre([7, 3, 0, 7]))  # 7307

Binaire en Python

binaire_python.py
nombre = 13
print(bin(nombre))              # '0b1101'
print(int('1101', 2))           # 13
print(0b1101)                   # 13

📋 Aide-mémoire

Chiffres2nombre : total = total*10 + chiffre (base 10).