"Tracey" <Tr****@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
I'm learning C++ and was stuck when writing code to convert a negative
decimal number string to a hexdecimal number. For example, suppose the
function interface is defined as:
int atoi( const char*, size_t radix)
One input string is "-1234" and radix is 16.
How to get the correct hexdecimal integer? Can anyone help ? Thanks in
advance!
Let's start by agreeing that all integers are stored in memory the same way.
There is no decimal vs. hexadecimal in memory. If what you want is the
hexadecimal representation of -1234, you can use this:
char hexOutput[20];
int res = atoi("1234");
itoa(res,hexOutput,16);
cout << endl << hexOutput << endl;