int a = 0x000001;
how would I printf() this or cout it so it displays as 0x000001?
outputing numbers
Moderator: Coders of Rage
- JaxDragon
- 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
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.
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.
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;
Last edited by JaxDragon on Sun Nov 14, 2010 7:19 pm, edited 1 time in total.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: outputing numbers
Code: Select all
printf("%#.6x",a);
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.
Re: outputing numbers
ya it was hex I was looking for, thanks ginto8 and JaxDragon
-
- 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
This is a great reference page, it's all you need language wise AFAIK.Ginto8 wrote:And this is where I got that infoCode: Select all
printf("%#.6x",a);