Jump to content
xisto Community

Kronenbier

Members
  • Content Count

    1
  • Joined

  • Last visited

  1. 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]; // 65That 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.
×
×
  • 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.