Created
February 5, 2011 19:25
-
-
Save underhilllabs/812701 to your computer and use it in GitHub Desktop.
translate binary number to decimal
This file contains hidden or 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
# 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