Reputation: 983
Nothing is displayed when I run the following. How should I correct it?
Compiler: g++
My intent: To store the value in binary/hexadecimal/octal and display is decimal equivalent
int main()
{
unsigned char c = 0b00001111;
cout << c << endl;
}
Upvotes: 0
Views: 132
Reputation: 70931
0b00001111
equals 15
and is a non-printable character.
Try 0b1000001
which equals 65
and should print an A
.
To get the 15
do:
cout << (int) c << endl;
For printable ASCII codes please see her: http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
Upvotes: 2