Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Bitwise inversion in java programming
Bitwise inversion in java programming
This problem involves the coding inside the computer. ?

For integers, most significant bit is used to represent sign bits, with 0 being positive and 1 being negative. ?

For negative numbers, in order to facilitate calculation, the computer uses complement to represent their values. ?

There is a complement of a number, and you should know that its value is divided into two situations:?

1: The sign bit is 0, which is a positive number, so the following binary bit indicates the size, that is, the original code of a positive number = its complement. If it is represented by 1, it is 000000 1 (I use 8 bits here, but I can also use 16 bits or 32 bits)?

2. The sign bit is 1, which is negative. At this time, you need to add one to the number behind (why? Look up the data, which can be deduced according to the characteristics of complement), so the number represented by111110 is11650. Counting the sign bit, it is -2. ?

In your case,

a=0=0000? 0000? 0000? 0000? 0000? 0000? 0000? 0000

~a? =? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 1 1 1 1? 111/the sign bit is1,and the following numbers are inverted and then+1.

1000? 0000? 0000? 0000? 0000? 0000? 0000? 000 1? =? - 1