The value of x & (-x) in 2 additions?

Where '-' denotes negative x and '&' denotes bitwise I.

The numbers are in an 8-bit complement in the program, and I can not find the correlation between inputs and outputs.

8  & (-8)  = 8
7  & (-7)  = 1
97 & (-97) = 1

So, is value possible in bit manipulation?

0000 1000 & (1111 1000) = 0000 1000
0000 0111 & (1111 1001) = 0000 0001
0110 0001 & (1001 1111) = 0000 0001

In each of the above cases, the upper 4-bits always end with 0, but I cannot find a correlation between the inputs and what the lower 4-bits end with.

Any ideas?

ANSWER: Find the least significant bit of a set

+4
source share
2 answers

To state another answer, two additions are equal to one addition of the number plus 1. Let's see how the addition of 1 to one addition to 8 goes.

8 -> 00001000 (bin) -> 11110111 (oc) -> 11111000 (tc)

, 1 , 0, . , 0 1 .

x & (-x) 1 x 0, . 1 0, 0 x ( ).

, x & (-x) 2, 1 x.

+1

( ) .

& , 0000 0000.

: + 1 . , 1 , - +1.

0

Source: https://habr.com/ru/post/1686769/


All Articles