Created
December 5, 2009 00:10
-
-
Save dlo/249477 to your computer and use it in GitHub Desktop.
Converts ints to binary strings.
This file contains 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
char *to_binary(int num) { | |
char s[9]; | |
int i; | |
strcpy(s, "00000000"); | |
for (i=0; i<8; i++) { | |
if (num & 01) | |
s[7-i] = '1'; | |
num >>= 1; | |
} | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment