HexToInt
March 5th, 2011
No comments
Several implementations of HexToInt function:
1. This implementation was in Chrome
inline unsigned char HexToInt(unsigned char c) { DCHECK(IsHexDigit(c)); static unsigned char kOffset[4] = {0, 0x30u, 0x37u, 0x57u}; return c - kOffset[(c >> 5) & 3]; }
2. From SQLite
return (c + 9 * (1 & (c >> 6))) & 15;
3. another version
return c - (0x57373000 >> (c >> 5) * 8);
or
return c - (0x57373000 >> ((c >> 5) << 3));
4. nobody will understand
return c - 128 + (c >> 5 & 3)["(PI)"];
or
return c - 128 + "(PI)"[(c >>5) & 3]