print hex value of character
Hi everyone,
Sorry for the noobish question, but I just started learning C++ (I learned C before) and got stuck on a really simple exercise:
Write a program that prints out the letters ´a ´..´z ´ and the digits ´0 ´..´9 ´ and their
integer values. Do the same for other printable characters. Do the same again but use hexadecimal notation.
Here's what I got so far:
Code:
int main()
{
cout << "a\t" << int('a') << endl
<< "b\t" << int('b') << endl
<< "c\t" << int('c') << endl
<< "d\t" << int('d') << endl
<< "e\t" << int('e') << endl
<< "f\t" << int('f') << endl
<< "g\t" << int('g') << endl
<< "h\t" << int('h') << endl
<< "i\t" << int('i') << endl
<< "j\t" << int('j') << endl
<< "k\t" << int('k') << endl
<< "l\t" << int('l') << endl
<< "m\t" << int('m') << endl
<< "n\t" << int('n') << endl
<< "o\t" << int('o') << endl
<< "p\t" << int('p') << endl
<< "q\t" << int('q') << endl
<< "r\t" << int('r') << endl
<< "s\t" << int('s') << endl
<< "t\t" << int('t') << endl
<< "u\t" << int('u') << endl
<< "v\t" << int('v') << endl
<< "w\t" << int('w') << endl
<< "x\t" << int('x') << endl
<< "y\t" << int('y') << endl
<< "z\t" << int('z') << endl
<< "0\t" << int('0') << endl
<< "1\t" << int('1') << endl
<< "2\t" << int('2') << endl
<< "3\t" << int('3') << endl
<< "4\t" << int('4') << endl
<< "5\t" << int('5') << endl
<< "6\t" << int('6') << endl
<< "7\t" << int('7') << endl
<< "8\t" << int('8') << endl
<< "9\t" << int('9') << endl
<< "{\t" << int('{') << endl
<< ".\t" << int('.') << endl
<< "+\t" << int('+') << endl;
return 0;
}
I know I could easily use a few loops and make it much shorter, but since the book didn't cover loops yet I just kept it expanded.
Now my problem is, I don't know how to output the character's hexadecimal value. Could someone point me out to the right direction? I searched google but I didn't find anything simple,