outputing numbers

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
polyneem
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 11
Joined: Tue May 11, 2010 7:23 pm

outputing numbers

Post by polyneem »

int a = 0x000001;
how would I printf() this or cout it so it displays as 0x000001?
User avatar
JaxDragon
Chaos Rift Junior
Chaos Rift Junior
Posts: 395
Joined: Mon Aug 04, 2008 2:03 pm
Current Project: Kanoba Engine
Favorite Gaming Platforms: PS3, PC
Programming Language of Choice: C++
Location: Northeast NC

Re: outputing numbers

Post 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.
Last edited by JaxDragon on Sun Nov 14, 2010 7:19 pm, edited 1 time in total.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: outputing numbers

Post by Ginto8 »

Code: Select all

printf("%#.6x",a);
And this is where I got that info
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
polyneem
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 11
Joined: Tue May 11, 2010 7:23 pm

Re: outputing numbers

Post by polyneem »

ya it was hex I was looking for, thanks ginto8 and JaxDragon
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Re: outputing numbers

Post 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.
Post Reply