Dec-21-2020, 03:36 AM
Hi folks! I gave myself a simple task of creating a function that turns binary numbers into decimal and was just wondering is there any way to make it a little bit more compact without using any extra modules? purely for practicing writing a tighter code.
def bi_to_dec(x): y=str(x) pwer= 0 totl = 0 for i in y[::-1]: power_multipler = int(i)*2**pwer totl+=power_multipler pwer+=1 return print(totl) bi_to_dec(10111)Cheers :)