codey modey
codey modey

Reputation: 983

Regarding storing in binary and displaying its decimal

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

Answers (1)

alk
alk

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

Related Questions