Home > Fresh News > HexToInt

HexToInt

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]
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.