Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

gesällprov 2 uppgift 8 andreas

def int2b(n,b):     # Convert n to base b
    token="0123456789abcdef"
    if b > 16 :
        return False
    kvot = rest = n_b = ""
    FMT = " {{:>{}}}".format(len(str(n)))
    OUT = "{} = ".format(n)
    while n :
        if n < b:
            FMT = "{}"
        kvot = FMT.format(str(n)) + kvot
        n,r = divmod(n,b)
        rest = FMT.format(token[r]) + rest
        n_b = token[r] + n_b
    OUT += "({})_{}:\n{}\n{}".format(n_b,b, kvot,rest)
    print(OUT)
    return
# --
int2b(9874398734,16)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.