View previous topic :: View next topic |
Author |
Message |
supercharger Advanced Cheater
Reputation: 0
Joined: 06 Aug 2009 Posts: 61
|
Posted: Wed May 05, 2010 3:58 am Post subject: what is the negative of 80 ? |
|
|
since
neg 0 = 0
neg 1 = ff
neg 7f = 81
then neg 80 = 80 ?
is it a positive value or negative value?
if 80 is negative value, then neg 80 should be a positive value, right?
but 80 = 80 , right?
|
|
Back to top |
|
 |
Pingo Grandmaster Cheater
Reputation: 8
Joined: 12 Jul 2007 Posts: 571
|
Posted: Wed May 05, 2010 5:08 am Post subject: |
|
|
Dont write it as byte value, use 2byte or 4byte
2byte
neg 0x80 = 0xFF80
pos 0x80 = 0x0080
4byte
neg 0x80 = 0xFFFFFF80
pos 0x80 = 0x00000080
_________________
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Wed May 05, 2010 7:42 am Post subject: |
|
|
look up two's complement on the internet
|
|
Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Wed May 05, 2010 7:46 am Post subject: |
|
|
Why don't you test it out yourself..
Code: | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
unsigned char c[] = { -0x00, -0x01, -0x7F, -0x80 };
int i;
for(i=0; i<sizeof(c); ++i)
printf("%x ", c[i]);
return EXIT_SUCCESS;
} |
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Wed May 05, 2010 7:51 am Post subject: |
|
|
Another easy way is to open up OllyDbg and double-click register values and play around with those since they have the representation in hex/binary/signed/unsigned.
|
|
Back to top |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Wed May 05, 2010 4:43 pm Post subject: |
|
|
if you talk about 1 byte then only the unsigned byte has a positive value 0x80 <-- which is +128 in decimal, unsigned byte is 0x00 - 0xFF equivalent 0-255 in decimal, but there are no negative values.
Now if you talk about signed byte, the number +128 in decimal does not fit in 1 byte because the signed byte is as follows
positives 0x00 - 0x7F ->> decimal 0 - +127 <-- +127 is the max positive that you can represent with 1 byte.
negatives 0x80 - 0xFF ->> decimal -128 - -1 (-128 is 0x80 and -1 is 0xFF)
So as you understand you'll need a second byte
which can handle 65535 different values.
So with 2 bytes -1 is 0xFFFF . So if 0x80 is +128 (unsigned) and 0xFFFF is -1 then you should go backwards and do 0xFFFF - 0x80 +1 (+1 because -1 -128 = -129) wich is 0xFF80 . I hope you'' figure it out time-time/.
EDIT: if you use the calculator and select WORD wich is 2 bytes, and type FF80 it will show the positive value because WORD is unsigned.
|
|
Back to top |
|
 |
|