New hex program

This commit is contained in:
Neale Pickett 2017-08-09 00:14:02 +00:00
parent 0c37c73a8e
commit 5dd38fb4ea
2 changed files with 35 additions and 0 deletions

View File

@ -12,6 +12,10 @@ Usually, a program expects input on stdin,
and produces output on stdout. and produces output on stdout.
Flags are sparse by design. Flags are sparse by design.
Fluffy source code is purposefully spartan and easy to audit.
Forks are encouraged,
please let me know if you make one.
How To Build How To Build
------------ ------------
@ -114,6 +118,15 @@ Removes duplicate frames from input,
writing to output. writing to output.
### hex: hex-encode input
The opposite of `unhex`.
The following is the equivalent of `cat`:
hex | unhex
### printfesc: printf escape input ### printfesc: printf escape input
Reads octets, Reads octets,

22
hex.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdio.h>
int
main(int argc, char *argv[])
{
size_t count;
for (count = 0; ; count += 1) {
int c = getchar();
if (EOF == c) {
break;
}
printf("%02x ", c);
if (7 == count % 8) {
putchar(' ');
}
}
putchar('\n');
return 0;
}