5859390743ceecc3c2b79c05340f77e05dfefe23
galt
  Wed Feb 13 16:50:07 2013 -0800
adding functions to decode hexstring to byte
diff --git src/lib/hex.c src/lib/hex.c
index c0ab199..54b8b4a 100644
--- src/lib/hex.c
+++ src/lib/hex.c
@@ -14,15 +14,34 @@
 /* convert byte to hexidecimal characters. 0 <= n <= 255. */
 {
 *hex++ = nibbleToHex(n >> 4);
 *hex++ = nibbleToHex(n & 0xf);
 }
 
 char *byteToHexString(unsigned char n)
 /* convert byte to hexidecimal string. 0 <= n <= 255. */
 {
 char hex[3];
 byteToHex(n, hex);
 hex[2] = 0;
 return cloneString(hex);
 }
 
+/* And the reverse functions: */
+
+char hexToNibble(char n)
+/* convert hexidecimal character to nibble. 0-9a-f. */
+{
+return n - ( n <= '9' ? '0' : ('a'-10) );
+}
+
+
+unsigned char hexToByte(char *hex)
+/* convert byte to hexidecimal characters. 0 <= n <= 255. */
+{
+unsigned char n = hexToNibble(*hex++);
+n <<= 4;
+n += hexToNibble(*hex++);
+return n;
+}
+
+