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)
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more