Integer storage - Hexadecimal/Octal
<p>I understand that integers are stored in binary notation, but I was wondering how this affects the reading of them - for example:</p>

<p>Assuming </p>

<pre><code>cin.unsetf(ios::dec); cin.unsetf(ios::hex); and cin.unsetf(ios::oct);
</code></pre>

<p>the user inputs</p>

<pre><code>0x43 0123 65
</code></pre>

<p>which are stored as integers. Now assume that the program wants to recognize these values as hex, oct, or dec and does something like this.</p>

<pre><code>void number_sys(int num, string&amp; s)
{
string number;
stringstream out;
out &lt;&lt; num;
number = out.str();
if(number[0] == '0' &amp;&amp; (number[1] != 'x' &amp;&amp; number[1] != 'X')) s = "octal";
else if(number[0] == '0' &amp;&amp; (number[1] == 'x' || number[1] == 'X')) s = "hexadecimal";
else s = "decimal";
}
</code></pre>

<p>the function will read all of the integers as decimal. I put in some test code after the string conversion to output the string, and the string is the number in decimal form.  I was wondering if there is a way for integers to keep their base notation.</p>

<p>Of course you could input the numbers as strings and test that way, but then there is the problem of reading the string back as an int. </p>

<p>For example:</p>

<pre><code>       string a = 0x43;
       int num = atoi(a.c_str());
       cout &lt;&lt; num; // will output 43
</code></pre>

<p>It seems like keeping/converting base notation can get very tricky. As an added problem, the hex, dec, and oct manipulators wouldn't even help with the issue shown above since the integer is being stored completely incorrectly, it's not even converting to a decimal.</p>
