Skip to content

Commit 5e0f47a

Browse files
committed
hexadecimal to decimal conversion
1 parent abe85a7 commit 5e0f47a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Hexadecimal to Decimal Conversion
3+
"""
4+
5+
6+
def __getdecimaldigits(digit):
7+
digits = ['0', '1', '2', '3', '4', '5', '6',
8+
'7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
9+
for x in range(len(digits)):
10+
if digit == digits[x]:
11+
return x
12+
13+
14+
def hexadecimal_to_decimal(n):
15+
main = 0
16+
temp = 0
17+
18+
inputsize = len(n)
19+
20+
for i in range(inputsize, 0, -1):
21+
main = main + 16 ** temp * __getdecimaldigits(n[i-1])
22+
temp += 1
23+
24+
return str(main)
25+
26+
27+
if __name__ == "__main__":
28+
29+
n = input("enter number")
30+
print(hexadecimal_to_decimal(n))

0 commit comments

Comments
 (0)