If you have the following code:
cout << hex << 10;
The output is ‘a’, which means the decimal 10 is converted into its hexadecimal value.
However, in the code below…
int n;
cin >> hex >> n;
cout << n << endl;
When input is 12, the output becomes 18. Can anyone explain the details of the conversion? How did it became a decimal value?
I’m interested in the point where it became an int. If broken down, it would be:
(( cin >> hex ) >> n);
Is this correct?
The hex manipulator only controls how a value is read – it is always stored using the same internal binary representation. There is no way for a variable to “remember” that it was input in hex.