| View previous topic :: View next topic |
| Author |
Message |
Henley Grandmaster Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 671
|
Posted: Wed Jul 30, 2008 10:52 pm Post subject: [C++] Converting hex to decimal? |
|
|
it's kinda hard to explain this but its like this:
my program reads a value for a pointer
i use a label to show the value
when the value is a negative it's like 4,XXX,XXX,XXX(its the number where you hex the negative value and make it back into a decimal value)
What i want to do is make it so then it wouldnt show the 4 billion value but show the negative value instead. help please |
|
| Back to top |
|
 |
DoomsDay Grandmaster Cheater
Reputation: 0
Joined: 06 Jan 2007 Posts: 768 Location: %HomePath%
|
Posted: Thu Jul 31, 2008 1:11 am Post subject: |
|
|
| In your case, check on wsprintf() |
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Thu Jul 31, 2008 8:40 am Post subject: |
|
|
? _________________
Gone |
|
| Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Thu Jul 31, 2008 6:13 pm Post subject: |
|
|
WHAT IS THIS NONSENSE?
JAVA? _________________
armed with this small butterfly net
i will face the world alone
& never be lonely. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Jul 31, 2008 6:47 pm Post subject: |
|
|
| Cx wrote: |
WHAT IS THIS NONSENSE?
JAVA? |
Uh... I think it's Borland C++. _________________
|
|
| Back to top |
|
 |
Cx Master Cheater
Reputation: 0
Joined: 27 Jul 2007 Posts: 367
|
Posted: Thu Jul 31, 2008 8:43 pm Post subject: |
|
|
| lurc wrote: | | Cx wrote: |
WHAT IS THIS NONSENSE?
JAVA? |
Uh... I think it's Borland C++. |
Haha. I'm just giving him a hard time. _________________
armed with this small butterfly net
i will face the world alone
& never be lonely. |
|
| Back to top |
|
 |
Henley Grandmaster Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 671
|
Posted: Thu Jul 31, 2008 9:12 pm Post subject: |
|
|
ty for the help guys but i found out why it showed that number  |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Aug 01, 2008 12:13 am Post subject: |
|
|
| aznkidtroll wrote: | ty for the help guys but i found out why it showed that number  |
guessing it was a case of signed / unsigned? |
|
| Back to top |
|
 |
Nuclear898 Grandmaster Cheater Supreme
Reputation: 0
Joined: 04 Jun 2006 Posts: 1597 Location: The Netherlands
|
Posted: Fri Aug 01, 2008 1:54 am Post subject: |
|
|
| Code: | #include <iostream>
int main( void )
{
char text[128];
int number;
printf("Which number do you want to convert to hex? ");
std::cin >> number;
sprintf(text,"%x",number);
printf("%d is %s in hex.\n",number,text);
std::cin.get();
std::cin.get();
} |
That's what I found some time ago, but you guys will probably say it's a bad way to do it or something... |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Aug 01, 2008 9:04 am Post subject: |
|
|
| Nuclear898 wrote: | | That's what I found some time ago, but you guys will probably say it's a bad way to do it or something... | :P More of a C++ way: | Code: | #include <iostream>
int main(int argc, char *argv[])
{
int i;
std::cout << "Num: ";
std::cin >> i;
std::cout << "Hex: " << std::hex << i;
return EXIT_SUCCESS;
} | std::hex works with stringstream and so on.. |
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Fri Aug 01, 2008 12:01 pm Post subject: |
|
|
use "(int)hex" ?
lol idk if it will works but i think it does. _________________
Gone |
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Fri Aug 01, 2008 3:52 pm Post subject: |
|
|
| Jani wrote: | | Nuclear898 wrote: | | That's what I found some time ago, but you guys will probably say it's a bad way to do it or something... |
More of a C++ way: | Code: | #include <iostream>
int main(int argc, char *argv[])
{
int i;
std::cout << "Num: ";
std::cin >> i;
std::cout << "Hex: " << std::hex << i;
return EXIT_SUCCESS;
} | std::hex works with stringstream and so on.. |
Yep. This will work |
|
| Back to top |
|
 |
GMZorita Grandmaster Cheater Supreme
Reputation: 0
Joined: 21 Mar 2007 Posts: 1361
|
Posted: Fri Aug 01, 2008 4:05 pm Post subject: |
|
|
| kitterz wrote: | | Jani wrote: | | Nuclear898 wrote: | | That's what I found some time ago, but you guys will probably say it's a bad way to do it or something... | :P More of a C++ way: | Code: | #include <iostream>
int main(int argc, char *argv[])
{
int i;
std::cout << "Num: ";
std::cin >> i;
std::cout << "Hex: " << std::hex << i;
return EXIT_SUCCESS;
} | std::hex works with stringstream and so on.. |
Yep. This will work |
He wants Hex->Int not Int->Hex. _________________
Gone |
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Sat Aug 02, 2008 12:44 am Post subject: |
|
|
| GMZorita wrote: | | kitterz wrote: | | Jani wrote: | | Nuclear898 wrote: | | That's what I found some time ago, but you guys will probably say it's a bad way to do it or something... |
More of a C++ way: | Code: | #include <iostream>
int main(int argc, char *argv[])
{
int i;
std::cout << "Num: ";
std::cin >> i;
std::cout << "Hex: " << std::hex << i;
return EXIT_SUCCESS;
} | std::hex works with stringstream and so on.. |
Yep. This will work |
He wants Hex->Int not Int->Hex. |
Windows Calc. |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sat Aug 02, 2008 5:27 am Post subject: |
|
|
| GMZorita wrote: | | He wants Hex->Int not Int->Hex. | I was replying to Nuclear898 (that's why the quote.). Also the same stuff works the other way round too, if you're enough smart to understand that. Btw.. Int is a integer, hex is a representation of the integer. | Code: | #include <iostream>
int main(int argc, char *argv[])
{
int i;
std::cout << "Num: ";
std::cin >> std::hex >> i;
std::cout << "Dec: " << std::dec << i;
return EXIT_SUCCESS;
} |
| Code: | ./a.out
Num: A
Dec: 10 |
|
|
| Back to top |
|
 |
|