| View previous topic :: View next topic |
| Author |
Message |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Dec 18, 2009 6:23 am Post subject: C++ hex problem |
|
|
okay so ive got a nice little C++ console app, cin cout and all that
and what im trying to do basically is have the user input a hex values like 0x00001122 or just 00001122 using cin and have a dword store that value so it can be used to read some memory, however it does not work as it is, it seems to give a decimal value which makes the program crash when it tries to use it
any ideas? im well stuck
_________________
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Fri Dec 18, 2009 10:34 am Post subject: |
|
|
I don't know how you are using cin, but I think you should be able to do something like:
| Code: | | cin >> hex >> variable; |
I don't know how it would work with other cin methods like cin.get()
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Dec 18, 2009 5:22 pm Post subject: |
|
|
the std::hex manipulator works on input as well.
set it back to std::dec if you need it back to normal.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Dec 18, 2009 8:51 pm Post subject: |
|
|
thanks for the help btw
ive been trying that too, heres the code
| Code: | DWORD Add, Off, Value;
cout << "Enter address: ";
cin >> hex >> Add;
cout << "Enter offset: ";
cin >> hex >> Off;
cout << "Reading address " << Add << " at offset " << Off << " ..." << endl; |
and when i tried 000011bc and 1b3, it says reading at address 4540 at offset 435
hmmm, i tried using hex on the output aswell, it gives me the right number, but without the leading zeros, so 11bc instead of 000011bc, does that mean i could just add those zero to the front and it would work?
_________________
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Dec 18, 2009 9:00 pm Post subject: |
|
|
| setfill()
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Dec 18, 2009 9:02 pm Post subject: |
|
|
You could just use printf (or if you plan on having UNICODE support: _tprintf) and just set it as a pointer format flag.
| Code: | | _tprintf(_T("Reading address: 0x%p at offset 0x%p"), Add, Off); |
_________________
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Dec 18, 2009 9:04 pm Post subject: |
|
|
| Snootae wrote: | | ... it gives me the right number, but without the leading zeros, so 11bc instead of 000011bc, does that mean i could just add those zero to the front and it would work? |
| Slugsnack wrote: | | setfill() |
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Dec 18, 2009 9:04 pm Post subject: |
|
|
ah, thank you guys
so just filling up the zeros should work?
i shall do that
_________________
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Dec 18, 2009 9:13 pm Post subject: |
|
|
| Fibonacci is rolling in his grave right about now.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Dec 18, 2009 9:18 pm Post subject: |
|
|
im sure he doesnt have a grave, or anything left by now
on a related note im still failing at getting a stupid dword with the value
_________________
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Dec 18, 2009 9:29 pm Post subject: |
|
|
Here is a little exercise for you.
Which number is 10?
- 000000000010.000000000000000
- 010
- 00000000000000000000000000000000000000000010
- 10
- All of the above.
(Yes, I'm aware if you prefix a number with 0 it is thought of as an octal... in programming. This is purely math.)
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Dec 18, 2009 9:38 pm Post subject: |
|
|
ooooooh, d, no wait, e, no wait, e and d
_________________
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Dec 18, 2009 9:55 pm Post subject: |
|
|
| Code: | #include <windows.h>
#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
DWORD Add, Off;
cout << "Enter address: ";
cin >> hex >> Add;
cout << "Enter offset: ";
cin >> hex >> Off;
cout << "Reading address " << hex << setfill('0') << setw(8) << Add;
cout << " at offset " << hex << setfill('0') << setw(8) << Off << " ..." << endl;
return 0;
} |
Despite Flyte having been given tens of thousands of dollars in scholarship money, numerous awards, and even attending a university that essentially pays him to go there, he is still full of shit. He has no interest in helping people, only showing off what little he knows.
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Dec 18, 2009 10:08 pm Post subject: |
|
|
| Slugsnack wrote: | | Despite Flyte having been given tens of thousands of dollars in scholarship money, numerous awards, and even attending a university that essentially pays him to go there, he is still full of shit. He has no interest in helping people, only showing off what little he knows. |
I'd argue that showing him that leading 0s do not matter, however imparted, is far more valuable than providing an answer to question he never asked. Though I'm sure you didn't realize that, since you clearly lack reading comprehension.
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri Dec 18, 2009 10:38 pm Post subject: |
|
|
im sure its your job to impart wisdom eh?
not just help with what im actually asking
thanks slugsnack
_________________
|
|
| Back to top |
|
 |
|