Created
August 12, 2012 01:08
-
-
Save khakimov/3328576 to your computer and use it in GitHub Desktop.
convert integer into a binary character representation
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
#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