Home > Fresh News > HexToInt

HexToInt

Several implementations of HexToInt function:

1. This implementation was in Chrome

[C]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];
}[/C]

2. From SQLite

[CPP]return (c + 9*(1 & (c>>6))) & 15;[/CPP]

3. another version

[CPP]return c – (0x57373000 >> (c >> 5)*8);[/CPP]

or

[CPP]return c – (0x57373000 >> ((c >> 5) << 3));[/CPP]

4.  nobody will understand

[CPP]return c – 128 + (c >> 5&3)[“(PI)”];[/CPP]

or

[CPP]return c – 128 + “(PI)”[(c>>5) &3][/CPP]

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.