Hi, If I have a char which holds a hex value such has 0x53, (S), how can I display this as "S"?
Code:
char test = 0x53;
cout << test << endl;
Thanks!
Hi, If I have a char which holds a hex value such has 0x53, (S), how can I display this as "S"?
Code:
char test = 0x53;
cout << test << endl;
Thanks!
There's no such thing as a variable that stores a hex value, or a decimal or octal value. Hex, octal, and decimal are just different ways of representing numbers to the compiler. The compiled code will represent everything in binary.
These statements all have the exact same effect (assuming the charset is ASCII):
test = 0x53; // hex
test = 'S'; // literal constant
test = 83; // decimal
test = 0123; // octal
So print the character the same way you would with any character, no matter how you assign it a value.
Just use the following, you have already answered your question:
using namespace std;
int main() {
char test = 0x53;
std::cout << test << std::endl;
return 0;
}