Jump to content
xisto Community
Sign in to follow this  
Kronenbier

What Is The C++ Equivalent To Ord() ?

Recommended Posts

Hi,

I'm new to C++.
I found this FAQ around here on a equivalent to other languages' ord() function to C++.
It says I can simply assign to a int, like this:

string s = "AB";int i = s[0]; // 65
That works, but I'm having issues.

Let me explain...
I'm writing a small game editor for an old game. I'll open a binary file and change a few bytes to alter game properties. So, it's not simply ASCII characters anymore.
For example, game money is stored as 3 bytes in a certain offset.

1002345 is stored as a hex string: 0F 4B 69 = F4B69 = 1002345.

If I open that file and print all 3 bytes:
string mon = this->readMoney();int c0 =  mon[0];int c1 =  mon[1];int c2 =  mon[2];cout << c0 << endl;cout << c1 << endl;cout << c2 << endl;
Prints 15, 75 and 105, which are 0F, 4B and 69. Great!

But I tried a different value and problems happened. I set money to 393131 and tried the same code.
Values printed: 5, -1 and -85.

What's wrong here?


Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.