Skip to content

Instantly share code, notes, and snippets.

@tmathmeyer
Created March 28, 2014 15:15
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 tmathmeyer/9835153 to your computer and use it in GitHub Desktop.
Save tmathmeyer/9835153 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
char* int2bin(unsigned short x){
int size = sizeof(x)*8;
char* res = malloc(size);
int i = size;
while(i>0){
i--;
res[size-1-i] = ((1<<i)&x) ? '1' : '0';
}
return res;
}
unsigned short convert(char pot)
{
return (~0)+(1<<(pot/8));
}
int main(int argc, char** argv)
{
char i;
for(;i<127;i++)
printf("%s\n", int2bin(convert(i)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment