From 2497c1392b81e093f4de2541a98746aebd449a7f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 26 Sep 2012 15:04:18 +0200 Subject: Initial commit --- hex2bin.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 hex2bin.c (limited to 'hex2bin.c') diff --git a/hex2bin.c b/hex2bin.c new file mode 100644 index 0000000..78efd60 --- /dev/null +++ b/hex2bin.c @@ -0,0 +1,28 @@ +#include +#include +#include + +int main() { + char c; + int n = 0; + int count = 0; + int skipLine = 0; + while ((c = getchar()) != EOF) { + if (skipLine && c != '\n') continue; + if (isxdigit(c)) { + ++count; + n <<= 4; + if (isdigit(c)) { + n |= c - '0'; + } else { + n += 10 + tolower(c) - 'a'; + } + } + if (count >= 2 || (count && !isxdigit(c))) { + putchar(n); + n = count = 0; + } + skipLine = c == '#'; + } + return 0; +} -- cgit v1.2.1