I\'m trying to convert a hex char
to integer as fast as possible.
This is only one line:
int x = atoi(hex.c_str);
Is there a faster way
In case you (or someone else) are actually converting an array of values, I made an AVX2 SIMD encoder and decoder that benchmarks ~12x faster than the fastest scalar implementation: https://github.com/zbjornson/fast-hex
The 16 hex values conveniently fit (twice) into a YMM register, so you can use PSHUFB
to do a parallelized lookup. Decoding is a bit harder and based on bit-wise ops.