From 5dd38fb4ea4deb235dd80f495133c907a4a6eec2 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 9 Aug 2017 00:14:02 +0000 Subject: [PATCH] New hex program --- README.md | 13 +++++++++++++ hex.c | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 hex.c diff --git a/README.md b/README.md index cb8a19f..1230354 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ Usually, a program expects input on stdin, and produces output on stdout. 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 ------------ @@ -114,6 +118,15 @@ Removes duplicate frames from input, writing to output. +### hex: hex-encode input + +The opposite of `unhex`. + +The following is the equivalent of `cat`: + + hex | unhex + + ### printfesc: printf escape input Reads octets, diff --git a/hex.c b/hex.c new file mode 100644 index 0000000..4097a22 --- /dev/null +++ b/hex.c @@ -0,0 +1,22 @@ +#include + +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; +}