No "oneliner", no. Also, your code looks broken.
You cannot use sizeof like this, you probably mean strlen() .
And you need to drop the character to an unsigned type so that it is safe.
So, something like this is possible:
void print_hex(const char *s) { while(*s) printf("%02x", (unsigned int) *s++); printf("\n"); }
Please note that I do not call strlen() , as it makes no sense to iterate over the line twice when this is done. :)
source share