Sunday, June 20, 2010

Bit of Hex Education

So I've started my Virtua Tennis Savegame editor, so in order to follow, I need to teach you about hex. So firstly, the easy stuff.

If you want to get properly confused, go to the Wiki Page but here's a nicer one:

http://www.itnewb.com/v/Introduction-to-Hexadecimal-or-Base-16-Number-System

Hex is base 16, i.e. numbers go from 1-16, we usually deal with base 10, (since that's the number of fingers we have), but hex is from 0 to 15, inclusive, so we get our 16.

Also instead of having 10 to 15, we have A-F, (aside, why A-F, why not A-Z and we get even more numbers?).

So therefore, lets take 29 in denary

Binary = 11101

Hex = 1D

So easier to store and easier to read, if that was just denary, the most we could store is 100 values from 00-99, in hex, we can store 00-FF which is 256 values.


Next thing to know is Endianness, so Big endian and Little Endian and Most Significant and Least Significant bit.

In a big endian systems, the most significant bit is the furthest to the right, go back to our 29 in binary.

16 8 4 2 1
1 1 1 0 1

So in this instance, the most significant bit is the bit in the 16's column and least significant bit is the 1's column. This is how everyone learns binary.

The Virtua Tennis Savegame is stored in LSB, so therefore in this case it'd be.

1 2 4 8 16
1 0 1 1 1

So once we figure out the values, you'll need to swap the values backwards in order to make the change, but since we are doing it in hex it'll be like this.

Hex = 0A 01

Big Endian = 0A 01 = 2561
Little Endian = 01 0A = 266

The reason I think it's stored in Little Endian is because the PC Port, was just emulated, from the Dreamcast version which runs in Little Endian.

http://www.netbsd.org/ports/dreamcast/faq.html#endian

So there's my Hex Education, I'm sure I'm missing stuff. This is just a tasty for when we start hacking the file.

0 comments:

Post a Comment