Created
March 28, 2014 15:15
-
-
Save tmathmeyer/9835153 to your computer and use it in GitHub Desktop.
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 <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