Skip to content

Instantly share code, notes, and snippets.

@khakimov
Created August 12, 2012 01:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khakimov/3328576 to your computer and use it in GitHub Desktop.
Save khakimov/3328576 to your computer and use it in GitHub Desktop.
convert integer into a binary character representation
#include <stdio.h>
void itob(unsigned int n);
int main()
{
itob(100);
return 0;
}
void itob(unsigned int n)
{
int i;
char buf[32];
for(i =0; i < 32; i++)
buf[i] = '0';
for(i = 31; n != 0; i--, n = n >> 1)
buf[i] = (n & 1) ? '1' : '0';
printf("%s\n", buf);
}
/*
100
oringinal 00000000000000000000000001100100
itob 00000000000000000000000001100100
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment