Last active
August 29, 2015 13:57
-
-
Save mshroyer/9414104 to your computer and use it in GitHub Desktop.
bin2hex golf
This file contains hidden or 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
| 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