July 4th, 2010, 09:00 PM
C# String Hex Reading
So basically, here's the problem: I'm trying to read a save file for a game that I didn't make myself. I have been able to read in things such as strings and boolean variables (simply by using Unicode chars to compare to the strings). However, I come across problems when I try to read little-endian encoded 32-bit integers. Here's the code I have right now:
Code: Select all
private int littleEndianToDecimal(string hexStart)
int result = 0;
char hex = hexStart.ToCharArray();
uint dec = new uint;
for (int iii = 0; iii < dec.Length; iii++)
dec[iii] = hex[iii];
MessageBox.Show(dec.ToString() + " " + dec.ToString() + " " + dec.ToString() + " " +
if (dec < 128)
result = (int)(dec * 16777216 + dec * 65536 + dec * 256 + dec);
uint invDec = new uint;
for (int iii = 0; iii < invDec.Length; iii++)
invDec[iii] = (~(uint)dec[iii]) + 1;
result = -1 * (int)(invDec * 16777216 + invDec * 65536 + invDec * 256 + invDec);
The string "hexStart" contains the characters I scan in. The idea is to convert them to their Unicode hex values, so ÿ becomes FF or 255. However, upon casting it to an integer, for some reason values such as FF become 65533 and whatnot, rather than their default Unicode hex values. Also, the message boxes are only in there for debugging purposes and will not be included in the final version.
If anyone has any ideas on why this isn't working or any sort of script that will accomplish the same task in a better manner, the help would be much appreciated. Thanks!
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.