Skip to content

Instantly share code, notes, and snippets.

@dlo
Created December 5, 2009 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlo/249477 to your computer and use it in GitHub Desktop.
Save dlo/249477 to your computer and use it in GitHub Desktop.
Converts ints to binary strings.
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