Address in Hex without a 0x?

Dec 22, 2010 at 5:51pm
I made a program to find the address of some simple variables, and it says that the address for them are 003AF79C for one and 003AF78C for the other. I know that this is in Hex (or at least I assumed so), but why does it start with 00 instead of the usual 0x?
Last edited on Dec 22, 2010 at 6:08pm
Dec 22, 2010 at 5:56pm
Hex is short for HEXADECIMAL which is 16 symbols representing numerical values 0 - 15. They are the following 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F. 'X' is not one of those symbols so storing it as a value any where in the variable would be detrimental.

What you are used to seeing with the 0x prefix is more to inform the reader that they are looking at hex then to serve any real function to the program.
Last edited on Dec 22, 2010 at 5:57pm
Dec 22, 2010 at 6:00pm
I knew that X wasn't used in counting C++, I just thought that a hexadecimal number always had the prefix 0x. Do hex numbers not always require the 0x if they are coming from the computer?
Dec 22, 2010 at 6:02pm
If you are outputting that with streams, the default is without 0x prefix.
See http://www.cplusplus.com/reference/iostream/manipulators/showbase/
Dec 23, 2010 at 12:38pm
Note that the examples above are padded with leading zeros because it's a 32 bit number.
Dec 24, 2010 at 8:17am
if you're using printf you can say:
printf("%0#32x",0xff);
which gives:
0x000000ff

use %0#32X for capitals.
Last edited on Dec 24, 2010 at 8:23am
Topic archived. No new replies allowed.