Sunday, January 17, 2016

#C: fast string to hex string

following this post, i have also added a method to convert a char* buffer to a char* buffer which holds the hex values of each input character.

e.g.:
HelloWorld -> 48656c6c6f576f726c64

a branchless method with a lookup table is used again. it works for any type of data (e.g. UTF-16, UTF-8, etc.) as long as sizeof(char) is 1 byte, as is in the standard.

the cfg2 C library now includes the function cfg_char_to_hex(), which can be found here.
it's effectively the reverse of cfg_hex_to_char().

--

0 comments: