# Thread: evaluating statements with bitwise operators

1. ## evaluating statements with bitwise operators

Hi

I wonder how I can find an example when ~n1 + ~n2==~(n1+n2) is true on signed integers. Normally the value of this expression is 0 but is it always? Is there a simple way to find a solution without running a code with loop that tests on range of numbers?

Another question:

lets define u2 as casted unsigned number of n2, same with u1 of n1

is this (int) (u1-u2) always equal to expression -(n2-n1)? Int before (u1-u2) means that substraction is done and the result is casted to a signed integer.

and what this means?

(n>>24) | ((n<<8) & 0x00FF0000)?

Thanks for any input!

2. ~n1 + ~n1 == ~(n1+n2) should be solvable for n2, once you picked an n1. Unless that second n1 was supposed to be an n2. Otherwise it might help to remember that ~n1 = -n1 (in one's complement) or ~n1 = -n1-1 (in two's complement).

For the third, | means or, so any bit that's "on" in either the left side or the right side will be "on" in the result. << is left shift, so all bits are moved over eight spots (the eight bits on the left to start with are gone), and zeroes are filled on from the right. >> means right shift; if n is negative, it is up to the implementation whether the sign bit is filled in from the right, or if zeroes are filled in.