Created
November 11, 2014 18:03
-
-
Save noahbass/ed321e69794b8549ebce to your computer and use it in GitHub Desktop.
convert a binary to an integer
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
b = '10' # binary input | |
b = b[::-1] | |
number = 0 | |
for i in b: | |
i = int(i) | |
if i != 0: | |
number += 2**i | |
print number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment