C++ convert string to hexadecimal and vice versa
A string like “Hello World” to hex format: 48656C6C6F20576F726C64. Ah, here you go: #include <string> std::string string_to_hex(const std::string& input) { static const char hex_digits[] = “0123456789ABCDEF”; std::string output; output.reserve(input.length() * 2); for (unsigned char c : input) { output.push_back(hex_digits[c >> 4]); output.push_back(hex_digits[c & 15]); } return output; } #include <stdexcept> int hex_value(unsigned char hex_digit) { … Read more