Search code examples
c++hexhexdump

Chars exadecimal to string conversion


I need a function that convert hexadecimal char pointer to string:

ex:

std::string Myfunction(char* hexacode)
{
 std::string output;
 //
 //
 return output;
}


std::string Result = Myfunction("\x55\x8B\xEC\x83\xEC\x14\x53\x56\x8B\x75\x0C");

In short I need to convert in string this parameter or similar.

Because in the output the backslash is a option can be a solution replace backslash with slash if is too complicate keep the backslash.

Many thanks !!


Solution

  • If you want the user to input the string, you don't have to care about anything, string escaping only happens for constant strings in the code file.

    If you don't want the constant strings in the code file to be escaped, no function conversion needed, just do this:

    "\\x55\\x8B\\xEC\\x83\\xEC\\x14\\x53\\x56\\x8B\\x75\\x0C"