c++ printf char as hex

C++
printf("%02x", (unsigned char) c);
Source

Also in C++: