Two's Complement

Started by doomkaiber001, November 21, 2010, 09:05:33 PM

Previous topic - Next topic

doomkaiber001

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.

doomkaiber001

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? :)

James0x57



Bully@Wiiplaza

#3
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:
My Wii hacking site...
http://bullywiihacks.com/

My youtube account with a lot of hacking videos...
http://www.youtube.com/user/BullyWiiPlaza

~Bully

wiiztec

If there's any code at all that you want to be button activated, or even able to toggle on & off, and I have the game, just PM me and I'll make it happen

James0x57



dcx2

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.

Skiller

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 ..

doomkaiber001

Maybe, but I'd prefer to see how it works first though. Thanks for verifying everything guys!

doomkaiber001

Just to check, do you add the one into the first available space going from the right?

James0x57


Binary     Decimal
110111     110999
   + 1        + 1
------     ------
111000     111000


dcx2

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

doomkaiber001

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?

doomkaiber001

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.

doomkaiber001

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?