How to convert the positive value of an aob into a negative value?

Asked

Viewed 50 times

0

Hello someone can help me with the following question ?

Example I have an aob that represents an item (cigarette) in a game ...

XX XX XX XX XX XX XX = cigarette

Xx XX XX XX XX XX XX XX 01 = 1 cigarette

XX XX XX XX XX XX XX XX 0A = 10 cigarettes

How to turn the item value into a negative value?

XX XX XX XX XX XX XX XX ?? = -10 cigarettes

If anyone can help me with that, I’d appreciate it

Thank you

1 answer

0

Try to do with Complement of 2 in binary.

Transform the value you want to convert into binary: 0A = 1010

Now do the inversion (NOT) of the binary, that is, the where is 0 will be and 1 and the where is 1 will be 0:

1010 = 0101

Some +1 in the result: 0101 + 0001 = 0110 and will have its negative number in binary: 0110.

The problem now is the identification of a "normal" number (pure binary) and a negative number (0110 in normal torque is 6). To solve this problem, the rest of the bits have to be used, for example:

The number 10 in 8 bits is: 0000 1010, when doing the inversion will be 1111 0101, sum +1 and will be 1111 0110, ready, this is -10 negative and "identified" in binary (number 6 is 0000 0110). Meanwhile doesn’t work for everyone the types of values.

For example: in the case of a int Signed that "reserves a space" for the identification of negative numbers, this operation would work normally. But with a int unsigned (where you do not have the "reserve" for a negative number), this would not work and the result would be 246.

Now with your value, come on:

Turns to binary:

0000 0000 0000 000A = 0000 0000 0000 1010

Does the inversion:

0000 0000 0000 1010 = 1111 1111 1111 0101

Sum +1:

1111 1111 1111 0101 + 0001 = 1111 1111 1111 0110

Now with binary negative number on hand, just turn to Hexadecimal: FFFF FFFF FFFF FFF6.

The result of -10 is FFFF FFFF FFFF FFF6. Try using this value in your Aob.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.