Hey everyone,
I'm trying to convert some values to ASCII characters.
I understand that this is possible through means of something like this:
std::cout << (char)0x31 << std::endl; // prints 1
std::cout << (char)0x4C << std::endl; // prints L
However, my problem is that i have char array that contains 4 elements. I'm trying to get each 2 elements from the array and from there use it to get its ASCII values. I took the approach of converting each character to a string and for each pair i added 0x to it. From there i tried to covert each pair to an int and followed by converting it to char so it resembled something similar to above. This did not turn out well as the conversion weren't working.
int main() {
char buffer[4] = {'3','1', '4', 'C'};
string ltemp;
string ltemp2;
string ltemp3;
string ltemp4;
for (int i = 0; i < 2; i++) {
ltemp = buffer[i];
ltemp2 = buffer[i+2];
ltemp3 = ltemp + ltemp2;
ltemp4 = "0x" + ltemp3;
cout << "0x" + ltemp3 << endl;
}
return 0;
}
Any help on how to approach this will be greatly appreciated