Page 1 of 1

outputing numbers

Posted: Sun Nov 14, 2010 7:04 pm
by polyneem
int a = 0x000001;
how would I printf() this or cout it so it displays as 0x000001?

Re: outputing numbers

Posted: Sun Nov 14, 2010 7:14 pm
by JaxDragon
So many questions I have about that code....

Are you trying to print it as hex? Do you know what hex is?

Heres one way, to print it with a being an integer in base 10.

Code: Select all

int a = 1; // With all those zeros in front of the one, without the '0x', I think that it would be octal, though im not %100 on that. This is the safe bet.
cout << "0x00000" << a << endl;
If a really has to be hex, and you need to print it as hex, please let me know. I will be happy to try and refactor my code.

Re: outputing numbers

Posted: Sun Nov 14, 2010 7:16 pm
by Ginto8

Code: Select all

printf("%#.6x",a);
And this is where I got that info

Re: outputing numbers

Posted: Sun Nov 14, 2010 7:21 pm
by polyneem
ya it was hex I was looking for, thanks ginto8 and JaxDragon

Re: outputing numbers

Posted: Sun Nov 14, 2010 10:26 pm
by pritam
Ginto8 wrote:

Code: Select all

printf("%#.6x",a);
And this is where I got that info
This is a great reference page, it's all you need language wise AFAIK.