public static void main(String[] args) { int a = -10 ; for(int i=0;i<32;i++){ int t = (a & 0x80000000>>>i)>>>(31-i); System.out.print(t); } // String binaryString = Integer.toBinaryString(-10); // System.out.println(binaryString); }
Second, the analysis process
in JAVA byte int 4 = 4 * 8 = 32 bit 32 bit
X : 10
II: 00000000000000000000000000001010 (original code, i.e. the number of machines)
trans: 11111111111111111111111111110101
complement: 11111111111111111111111111110110 (i.e., the original code's complement negative of the original code )
ten: -10 (negative number: the original code of the positive number is inverted plus 1, that is, the complement of the original code)
two: 1111111111111111111111111110110
>>> Forced to move to the right, the priority is higher than &
0x hex
0x80000000 = 10000000000000000000000000000000 (b)
I = 0
10000000000000000000000000000000 >>> 0 = 10000000000000000000000000000000
10000000000000000000000000000000
& 11111111111111111111111111110110
---------------------------------
10000000000000000000000000000000
10000000000000000000000000000000 >>> 31 = 1
i=1
>>> 1 = 10000000000000000000000000000000 01000000000000000000000000000000
01000000000000000000000000000000
& 11111111111111111111111111110110
---------------------------------
01000000000000000000000000000000
01000000000000000000000000000000 = 30 1 >>>
a & 0x80000000>>>i Take the i-th bit on the left side of a, and the rest of the bits are 0
(a & 0x80000000>>>i)>>>(31-i) Shift 31-i bits to the right, and add 0 to the left , after the move, the i-th digit of the above operation is left, that is, the i-th digit is moved to the last digit of the most digit, and all 0s are on the left
.
Function
expression )