Skip to content

Instantly share code, notes, and snippets.

@abenson
Created July 17, 2018 21:26
Show Gist options
  • Save abenson/0d2065e9f7819f346d7db5992108ee48 to your computer and use it in GitHub Desktop.
Save abenson/0d2065e9f7819f346d7db5992108ee48 to your computer and use it in GitHub Desktop.
bin2chr
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
int main(int argc, const char *argv[])
{
uint8_t b = 0, c = 128;
int i;
if(argv[1] == NULL) {
return 1;
} else if(strlen(argv[1]) != 8) {
return 2;
}
for(i=0; i<8; i++) {
if(argv[1][i] == '1') {
b |= c;
}
c = c >> 1;
}
printf("%c", b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment