There is a certain line (with an even number of characters), for example "4AABC1FD".
It must be represented in hexadecimal bytes, for example, "\ x4A \ xAB \ xC1 \ xFD".

    1 answer 1

    Yes. Quite possibly with standard C ++ tools.

    std::string str_hex = "4AABC1FD"; uint32_t hx = std::stol(str_hex,nullptr,16); std::cout << std::hex << hx << std::endl; 

    You can use the following line to represent an array of characters:

     char *out = reinterpret_cast<char*>(&hx); 

    The sequence of bytes (direct or inverse) will be determined by the processor architecture.

    • This is not exactly what is needed, I would like to do this char source[] = "4AABC1FD"; => char out = "\x4A\xAB\xC1\xFD"; - clay
    • @clay Ie Do you just need to insert every two \x characters? - Max ZS
    • Damn it, I hurt hard. Thus, it will be possible to use this string as a sequence of bytes, not characters? - clay
    • @clay So do you think that what I gave in the answer is not a sequence of bytes? The number hx in my answer is a sequence of 4 bytes. Look at & hx and see your numbers. Depending on the processor architecture, these bytes will be either in direct or in reverse order. - Max ZS
    • one
      @clay out is a pointer. You are trying to display a memory area. This is not a string that ends in zero. If you want, you can close it with zero. - Max ZS