On Tue, Apr 08, 2008 at 02:41:23AM +0200, Uwe Hermann wrote:
+u8 bin2hex(u8 b) +{
- return "0123456789abcdef"[b & 15];
+}
Neat. :)
+u8 hex2bin(u8 h) +{
- return (('0' <= h && h <= '9') ? (h - '0') : \
('a' <= h && h <= 'f') ? (h - 'a' + 10) : 0);
+}
Might be worth mentioning in doxygen that the return value is 0 for invalid characters.
Also might be worth clarifying that these two only work on a nibble rather than a full byte.
//Peter