Skip to content

Instantly share code, notes, and snippets.

@mshroyer
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save mshroyer/9414104 to your computer and use it in GitHub Desktop.

Select an option

Save mshroyer/9414104 to your computer and use it in GitHub Desktop.
bin2hex golf
int main(int a, char *v[]) {
sscanf(v[1], "%x", &a);
void *fi=fopen(v[2], "r"), *fo=fopen(v[3], "w");
for (unsigned char s=a/256+a, c[32], n; n=fread(c, 1, 32, fi); a+=n, s=a/256+a) {
fprintf(fo, ":%02X%04X00", n, a);
for (int i=0; i<n; s+=c[i++]+1) fprintf(fo, "%02X", c[i]);
fprintf(fo, "%02X\n", (256-s)&255);
}
fputs(":00000001FF\n", fo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment