WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: doomkaiber001 on November 21, 2010, 09:05:33 PM

Title: Two's Complement
Post by: doomkaiber001 on November 21, 2010, 09:05:33 PM
Could someone explain Two's complement to me? I think it's something to do with hex, and that its a negative number. That's all I know. Thanks.
Title: Re: Two's Complement
Post by: doomkaiber001 on November 21, 2010, 09:30:15 PM
Problem solved!

To work out -05, first work out positive 5 = 00000101 (Written in 8 bit to save time).
Then invert the 1s and 0s; 00000101 becomes 11111010.
Then add 1 = 11111011
-5 = 11111011 Am I right? :)
Title: Re: Two's Complement
Post by: James0x57 on November 21, 2010, 09:49:13 PM
yep
Title: Re: Two's Complement
Post by: Bully@Wiiplaza on November 21, 2010, 10:13:17 PM
http://geckocodes.org/index.php?arsenal=3
use james´ tool :D
it´s lulz to have a negative amount of score or ammo XD

-5 = FFFFFFFB ! :rolleyes:
Title: Re: Two's Complement
Post by: wiiztec on November 21, 2010, 10:36:31 PM
C0A00000 is cooler
Title: Re: Two's Complement
Post by: James0x57 on November 22, 2010, 12:05:24 AM
-559038737
Title: Re: Two's Complement
Post by: dcx2 on November 22, 2010, 12:29:29 AM
Yes, flip the bits and add 1.  The same process in reverse will turn negative numbers into positive numbers.  We use two's complement because the same exact circuits can be used to add negative numbers to positive numbers.  For example, -1 = 0xFF and 1 = 0x01.  Add them together and you get 0x100, but since we're only using 8 bits the MSB is truncated, leaving 0x00.  Which makes sense, 1 + -1 = 0.

Note that this only applies to SIGNED integers.  If a value is UNSIGNED, then it can't be negative; the formerly-negative numbers now become even larger positive numbers.  So, a signed 16-bit number maxes out at 32767, while an unsigned 16-bit number maxes out at 65535.

Also, instead of commas, we use spaces every 4 bits.  0000 0101 = 0x05.  Hex numbers SHOULD be preceded with 0x to denote base 16, but lots of people leave it off.  I tend to leave it off only for addresses.

Finally...ask questions like this in Wii Game Hacking Help.  I'm moving this thread there again, too.
Title: Re: Two's Complement
Post by: Skiller on November 22, 2010, 02:29:39 AM
Quote from: doomkaiber001 on November 21, 2010, 09:30:15 PM
Problem solved!

To work out -05, first work out positive 5 = 00000101 (Written in 8 bit to save time).
Then invert the 1s and 0s; 00000101 becomes 11111010.
Then add 1 = 11111011
-5 = 11111011 Am I right? :)

u could just use the Windows Calculator ..

that + - button will alow u to change your Dec Number to Negative or Positive then just Click on the Hex box to change it to Hex after ..
Title: Re: Two's Complement
Post by: doomkaiber001 on November 22, 2010, 07:30:26 AM
Maybe, but I'd prefer to see how it works first though. Thanks for verifying everything guys!
Title: Re: Two's Complement
Post by: doomkaiber001 on November 22, 2010, 07:33:37 AM
Just to check, do you add the one into the first available space going from the right?
Title: Re: Two's Complement
Post by: James0x57 on November 22, 2010, 01:55:47 PM

Binary     Decimal
110111     110999
   + 1        + 1
------     ------
111000     111000
Title: Re: Two's Complement
Post by: dcx2 on November 22, 2010, 01:57:46 PM
No, you add one just like you add one to any other number.  5 + 1 = 6, right?  Well, in binary, when we do that, there will be a 1 that carries (noted in ()'s)

 (1)
0101
0001
+___
0110
Title: Re: Two's Complement
Post by: doomkaiber001 on November 22, 2010, 05:15:10 PM
Oh... I get it now. I thought that if it was 0000 0001, you'd make it 0000 0011. But it's 0000 0010, isn't it?
Title: Re: Two's Complement
Post by: doomkaiber001 on November 22, 2010, 05:31:18 PM
Can someone direct me to a link which explains signed integers in detail? I'm sure I found one before, but can't find it now (even with the search bar). Thanks.
Title: Re: Two's Complement
Post by: doomkaiber001 on November 22, 2010, 08:13:50 PM
Ok, I googled signed integers and found the following out;

10000000 could be a signed integer, because the bit on the far left (Sign Bit) is a one.

00000001 has to be a unsigned integer, because the sign bit is a zero.


So, how would you put a negative hex into a code using the Wiird GUI?
Title: Re: Two's Complement
Post by: dcx2 on November 22, 2010, 08:44:21 PM
Bits are just bits.  By themselves, they have no meaning.  It is how you treat the bits that matters.

For instance, consider the 8-bit value 0x41.  In binary, this is 0100 0001.  If you treat this value as a signed integer, it is 65.  If you treat it as an unsigned integer, it is 65.  If you treat it as an ASCII character, it is the letter A.  It's as if 0x41 has multiple personalities!

Now consider the 8-bit value 0xFE.  In binary, this is 1111 1110.  If you treat it as a signed integer, it is -2.  If you treat it as unsigned, it is 254.  If you treat it as ASCII, you get garbage; ASCII only defines 0x00 through 0x7F.
Title: Re: Two's Complement
Post by: doomkaiber001 on November 22, 2010, 09:06:38 PM
Ok, what on earth is ASCII?
Title: Re: Two's Complement
Post by: James0x57 on November 22, 2010, 11:52:59 PM
It's one set (most common, I think..) of universal binary values for plain text characters. http://www.asciitable.com/
More info at google.


@dcx2
https://developer.mozilla.org/en/JavaScript_typed_arrays/ArrayBufferView
Sexy, right? JavaScript 2.0 ftw! haha
Title: Re: Two's Complement
Post by: doomkaiber001 on November 23, 2010, 07:27:31 AM
Are the symbols in red ASCII? Do I need to actually know about it to hack?
Title: Re: Two's Complement
Post by: James0x57 on November 23, 2010, 05:40:27 PM
No.

Unless you want to hack the text in the game.
Title: Re: Two's Complement
Post by: doomkaiber001 on November 23, 2010, 05:44:24 PM
Well, there's probably no use in that then... Ok, thanks for explaining everything to me!
Title: Re: Two's Complement
Post by: benny3t3 on November 23, 2010, 07:27:08 PM
Hacking the text in a game, that sounds cool. Maybe I'll look into that sometime...
Title: Re: Two's Complement
Post by: megazig on November 24, 2010, 11:56:40 AM
Quote from: doomkaiber001 on November 22, 2010, 08:13:50 PM
Ok, I googled signed integers and found the following out;

10000000 could be a signed integer, because the bit on the far left (Sign Bit) is a one.

00000001 has to be a unsigned integer, because the sign bit is a zero.


So, how would you put a negative hex into a code using the Wiird GUI?

assuming binary notation
00000001 can be signed too, just that it's a positive signed char (+1)