Skip to content

Instantly share code, notes, and snippets.

@underhilllabs
Created February 5, 2011 19:25
Show Gist options
  • Save underhilllabs/812701 to your computer and use it in GitHub Desktop.
Save underhilllabs/812701 to your computer and use it in GitHub Desktop.
translate binary number to decimal
# binary number to decimal
def bin_to_dec(num):
total = 0
i = 0
for dig in str(num)[::-1]:
total += int(dig) * int(pow(2,i))
i = i + 1
return total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment