[Solved] How to represent unsigned char values as hexadecimal string?


I want to get a return values 3374747372 as char or string.

Casting doesn’t work in this case.

You can use text formatting IO to get a hex string representation of the arrays content:

unsigned char codeslink[5] ={ 0x33, 0x74, 0x74, 0x73, 0x72};
std::ostringstream oss;
oss << std::hex << std::setfill('0');
for(size_t i = 0; i < 5; ++i) {
    oss << std::setw(2) << (unsigned int)codeslink[i];
}
std::string result = oss.str();

Live Demo

5

solved How to represent unsigned char values as hexadecimal string?