I'm trying to print a sequence of bytes with the function below, however I'm experiencing something strange, the character 0xED for example, which should be a latin small letter i with acute, is printed as � (a strange character with a question mark inside, as though it can't be printed). Is it due to my code, or the console I print it in ?
Also, is the code correct, or what would you have done differently to improve it ?
Edit: output example
1F 8B 08 00 00 00 00 00 97 86 22 0D 89 72 EC 04 ........ .."..r�.
Thanks
void printBytes(std::string string) {
QDebug qD = qDebug().nospace();
qD << "Printing string of size " << string.size() << "\n";
char buffer [3];
int j = 0;
std::string printable = "";
for (uint32_t i = 0; i != string.size(); ++i) {
snprintf(buffer, sizeof(buffer), "%02X", (unsigned char) string.at(i));
qD << buffer;
printable += QChar(string.at(i)).isPrint() ? string.at(i) : '.';
printable += j == 7 ? " " : "";
if (j == 15) {
qD << "\t" << printable.c_str() << "\n";
printable = "";
j = 0;
} else {
qD << (j == 7 ? " " : " ");
j++;
}
}
if (j != 0) {
qD << std::string((16-j) * 3, ' ').c_str() << "\t" << printable.c_str();
}
}