Python: Hexadecimal to Decimal Conversion

preview_player
Показать описание
How to write a Hexadecimal to Decimal Conversion program in Python 3
Рекомендации по теме
Комментарии
Автор

# HEXADECIMAL TO DECIMAL (Works Fine!)
x=input("Enter hexadeci: ")

t=[X for X in x] #Takes input of hexa and add all in one list seperately as a string.



n=len(t)-1 #This is power

HEXA=0 #We will add to this variable

for i in range(len(t)):

if t[i]== "A" or t[i]== "a":

t[i]=10

elif t[i]== "B" or t[i]== "b":

t[i]=11

elif t[i]== "C" or t[i]== "c":

t[i]=12

elif t[i]== "D" or t[i]== "d":

t[i]=13

elif t[i]== "E" or t[i]== "e":

t[i]=14

elif t[i]== "F" or t[i]== "f":

t[i]=15

else:

t[i]=int(t[i])



add=t[i]*(16**n) #N*(16)^n looks like this N=hexa number. n=power.

HEXA+=add

n-=1



print("Decimal of hexadecimal number", x, "is ", HEXA)

uthpakhi
Автор

It's a good video! However, I think you should pace down your rhythm a little. I had to pause the video often to assimilate what you were doing and saying. Nevertheless, thank you!

gregoriodaluzz
Автор

How to convert hexa to decimal..hexa is (2A)16=decimal is (?)10...so please suggested me...thank you sir

kimbumkimbum
Автор

I want my hex value to be inputted via shell, does anyone know what to code for that?

yeenyweeny
Автор

the line 'return x' gives out a syntax error so needs some working out for those who thinks this video is the answer for what you need.

withernet
Автор

how about:
print(int("1A", 16))

aashiqahmed