Created
July 7, 2014 06:14
-
-
Save Prince781/e2c1352a4c5f096e90da to your computer and use it in GitHub Desktop.
Binary string to number converter
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
| #include <stdio.h> | |
| unsigned bintoint(char s[]) { | |
| int i, l; | |
| unsigned v = 0; | |
| for (l=-1; s[l+1] != '\0'; ++l); | |
| for (i=l; i>=0; --i) | |
| v += (s[i]-'0')<<(l-i); | |
| return v; | |
| } | |
| int main(int argc, char *argv[]) { | |
| if (argc > 1) printf("%u\n", bintoint(argv[1])); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment