Sha256: e06c050a93c5260bafb58b744fa3a4bd20e8d9050256b53d35620a3129f38c89
Contents?: true
Size: 971 Bytes
Versions: 1
Compression:
Stored size: 971 Bytes
Contents
/////////////////////////////////////////////////////////////////////////////// // /// \file hex2bin.c /// \brief Converts hexadecimal input strings to binary // // Author: Lasse Collin // // This file has been put into the public domain. // You can do whatever you want with this file. // /////////////////////////////////////////////////////////////////////////////// #include "sysdefs.h" #include <stdio.h> #include <ctype.h> static int getbin(int x) { if (x >= '0' && x <= '9') return x - '0'; if (x >= 'A' && x <= 'F') return x - 'A' + 10; return x - 'a' + 10; } int main(void) { while (true) { int byte = getchar(); if (byte == EOF) return 0; if (!isxdigit(byte)) continue; const int digit = getchar(); if (digit == EOF || !isxdigit(digit)) { fprintf(stderr, "Invalid input\n"); return 1; } byte = (getbin(byte) << 4) | getbin(digit); if (putchar(byte) == EOF) { perror(NULL); return 1; } } }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
laag-xz-5.2.4.0 | vendor/git.tukaani.org/xz/debug/hex2bin.c |