IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Voir le flux RSS

Tous les billets

  1. Python. Convertir un nombre décimal en hexadécimal sans utiliser hex(dec)

    par , 10/11/2019 à 00h06
    Pour un débutant, cela ne me semble pas aussi simpliste que certains le disent.

    Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    #! python3
    # coding: utf-8
     
    from math import trunc
     
    # dict mapping dec -> hexa
    D2H = dict(zip(range(16), "0123456789abcdef"))
     
     
    def to_hex(n: int) -> str:
        lst = []
        while True:
            if n >= 16:
                quotient = trunc(n / 16)
                reste = n % 16
                lst.append(str(D2H[reste]))
    ...

    Mis à jour 10/11/2019 à 09h14 par danielhagnoul

    Catégories
    Python , Python , Programmation
Page 3 sur 3 PremièrePremière 123