Skip to content

Instantly share code, notes, and snippets.

@albertlai431
Created July 3, 2019 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertlai431/8082a0ea6ece00d2c9575309782181dd to your computer and use it in GitHub Desktop.
Save albertlai431/8082a0ea6ece00d2c9575309782181dd to your computer and use it in GitHub Desktop.
#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