Meaning of bitwise and(&) of a positive and negative number?
问题 Can anyone help what n&-n means?? And what is the significance of it. 回答1: I believe it is a trick to figure out if n is a power of 2. (n == (n & -n)) IFF n is a power of 2 (1,2,4,8). 回答2: It's an old trick that gives a number with a single bit in it, the bottom bit that was set in n . At least in two's complement arithmetic, which is just about universal these days. The reason it works: the negative of a number is produced by inverting the number, then adding 1 (that's the definition of two