From 1bee6f9b9c456854feff78a72d7ac3fb915454af Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Fri, 4 Apr 2008 13:16:33 +0000 Subject: [PATCH] Add BIN2HEX and HEX2BIN macros (trivial). They're generally useful for lots of stuff, but especially for converting to/from the compact 160 bit (20 byte) representation of SHA-1 hashes to the "hex" representation (same as 'sha1sum' output), which is 40 bytes long. Signed-off-by: Uwe Hermann Acked-by: Uwe Hermann git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3213 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- payloads/libpayload/include/libpayload.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index 5595ff6978..2cdb0d00f6 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -41,6 +41,10 @@ #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#define BIN2HEX(b) ("0123456789abcdef"[b & 15]) +#define HEX2BIN(h) (('0' <= h && h <= '9') ? (h - '0') : \ + ('a' <= h && h <= 'f') ? (h - 'a' + 10) : 0) + #define LITTLE_ENDIAN 1234 #define BIG_ENDIAN 4321 #ifdef CONFIG_TARGET_I386