Created
July 3, 2019 21:44
-
-
Save albertlai431/8082a0ea6ece00d2c9575309782181dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#getting the hexadecimal digits | |
def _getDecDigit(digit): | |
digits = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'] | |
for x in range(len(digits)): | |
if digit.lower() == digits[x]: | |
return(x) | |
#convert from hexadecimal to decimal | |
def hexToDec(hexNum): | |
decNum = 0 | |
power = 0 | |
for digit in range(len(hexNum), 0, -1): | |
try: | |
decNum = decNum + 16 ** power * _getDecDigit(hexNum[digit-1]) | |
power += 1 | |
except: | |
return | |
return(int(decNum)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment