Writing a function in Python 3 to convert base 16 to base 10 -


is there easy way modify code converts base 2 base 10 work converting base 16 base 10? objective build dedicated function conversion , not use built-in python features calculation. thanks

binaryval = int(input('enter:') decval = 0 n in range(len(str(binaryval))):     power = len(str(binx))-(n+1)     decval += int(str(binaryval)[n])*(2**power) print(decval) 

yikes.

int can convert base base 10 - supply second argument.

int('101010',2) out[64]: 42  int('2a',16) out[66]: 42 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -