Skip to content

Instantly share code, notes, and snippets.

@mazurov
Created September 18, 2014 18:00
Show Gist options
  • Select an option

  • Save mazurov/fd04d5318efd44ed7909 to your computer and use it in GitHub Desktop.

Select an option

Save mazurov/fd04d5318efd44ed7909 to your computer and use it in GitHub Desktop.
5.7 Base conversion
# 5.7 Base conversion
def base10(s, b):
res = 0;
for c in s:
res = res * b + (ord(c)-ord('0') if ord(c) <= ord('9') else 10 + ord(c) - ord('A'))
return res
x = base10('AA',16)
print(x)
x = base10('111',2)
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment