Try to do with Complement of 2 in Binary .
Transform the value you want to convert to binary: 0A
= 1010
Now do the inversion ( NOT
) of the torque, that is, where is 0 will be and 1 and a where 1 will be 0:
1010 = 0101
Add +1 to the result: 0101 + 0001 = 0110
and it 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 binary is
6
). To solve this problem, you have to use the rest of the bits, for example:
The number 10 in 8 bits is: 0000 1010
, when doing the inversion it will be 1111 0101
, sum +1 and it will be 1111 0110
, ready, this and the -10 "identified" in binary (the number 6 is 0000 0110
). However does not work for all variable types.
For example: In the case of a int signed that "reserves a space" for the identification of negative numbers, this operation would function normally. But with an int unsigned (where you do not have the "buffer" for a negative number), this would not work and the result would be 246
.
Now with your value, come on:
Transform to binary:
0000 0000 0000 000A = 0000 0000 0000 1010
Do the inversion:
0000 0000 0000 1010 = 1111 1111 1111 0101
Sum +1:
1111 1111 1111 0101 + 0001 = 1111 1111 1111 0110
Now with the binary negative number in hand, simply transforms to Hexadecimal: FFFF FFFF FFFF FFF6
.
The result of -10 is FFFF FFFF FFFF FFF6
. Try to use this value in your AoB.