Aug-10-2020, 08:48 AM
As it posted under 'General coding help' then I suggest using numpy.base_repr.
If it seems overkill to use numpy for simple conversion then using divmod makes code simpler (works for up to base 10):
If it seems overkill to use numpy for simple conversion then using divmod makes code simpler (works for up to base 10):
def convert(integer, base): base_digits = [] while integer: integer, base_digit = divmod(integer, base) base_digits.append(str(base_digit)) return ''.join(reversed(base_digits)) # convert(100, 2) -> '1100100' # convert(100, 3) -> '10201' # convert(100, 8) -> '144' # convert(100, 10) -> '100'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.