Created
October 14, 2015 13:57
-
-
Save Xophmeister/446a57eb72933ed2edbb to your computer and use it in GitHub Desktop.
Binary string to 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
| int bin2int(const char* s) { | |
| int out = 0; | |
| while (*s) { | |
| out <<= 1; | |
| if (*s == '1') ++out; | |
| ++s; | |
| } | |
| return out; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment