Public classTest1 { Public Static voidMain (string[] args) {/*The symbol is: Highest bit at the same time, 0 is a positive number, 1 is negative*/ /** 1, binary conversion to decimal * * Binary conversion to 10 binary rule is: The value of each bit * 2 (the current bit minus 1) * For example: 00000001 = 0 * 2^7 + 0 * 2^ 6 +0 * 2^5 * + 0 * 2^4 + 0 * 2^3 + 0 * 2^2 + 0 * 2^1 + 1 * 2^0 = 1 * 00000010 = 0 * 2^7 + 0 * 2^6 + 0 * 2^ 5 * + 0 * 2^4 + 0 * 2^3 + 0 * 2^2+ 1 * 2^1 + 0 * 2^0 = 2 * * 2, binary sign bit: highest bit denotes sign bit, 0 indicates positive number, 1 indicates negative number * 3. Convert binary negative to decimal: first reverse the binary number, then add 1, then convert to decimal, then precede with the minus sign * For example: 10101011 the highest bit is 1, so it is negative. * First step: Reverse: 0101 0100, * Step two: Add 1:0101 0101, * Step three: Convert to 10:85 * Step fourth: Plus minus:-85. * So 1010 1011 is converted to decimal-85 * * 4, the decimal negative number is converted to binary: the absolute value of the decimal negative number is first obtained, then the binary is converted into binary, then the binary is reversed, and then 1 * For example: 85 * First step: Get absolute Value 85 * Second step: Convert to Binary: 0101 0101 * Step three: Reverse: 1010 1010 * Fourth Step: Add 1:1010 1011 * So, 85 rpm Change to binary for 1010 1011*/ /*The ' non ' operator is the inverse of the target number, i.e. 0 becomes 1 and 1 becomes 0. * For example: 2 of the binary code is 00000010, it takes the inverse of 11111101. * Visible inverse result is negative (binary negative number is converted to decimal step: binary negation, then + 1) * Convert 1111 1101 to 10 binary * First step: Get back 0000 0010, * Step two: Add 1, get 0000 0011, the result is 3, * step three: in front of the minus sign can be * So the result is-3*/System.out.println (~); /** ^ xor, calculated as: two binary digits of the same bit is 0 different then 1 * 23 is converted to binary: 0001 0111 * 12 is converted to binary: 0000 1100 * ————————— * Calculated as: 0001 1011 =*/System.out.println (23 ^ 12); /** & Bitwise AND, calculated as: Two binary number of bits are 1 is 1, otherwise 0 * 1 of the binary is: 0000 0001 * 2 of the binary is: 0000 0010 * ————————— * Result: 0000 0000 = 0*/System.out.println (1 & 2); /** | bitwise OR, calculated as: two bits have a 1 is 1, no 0 * 5 binary is: 0000 0101 * 6 of the binary is: 0000 0110 * ————————— * Result: 0000 0111 = 7*/System.out.println (5 | 6); /** >> "signed" Right SHIFT, * the left side of the symbol indicates the number to be shifted, the right side indicates the number of digits to be shifted, the result is positive for the left 0, otherwise 1 * 3 of the binary is: 0000 0011 * First step: Move right 1 bits: the lowest bit to the right of 1 is removed 000 0001 * Second step: is positive, the highest bit left is 0, 0000 0001 = 1. */System.out.println (3 >> 1); /**-3 default int type 32 bit * Convert binary First: * Absolute value: 3 * absolute value binary: 0000 0000 0000 0000 0000 0000 0000 0011 * Take reverse: 1111 1111 1111 1111 1111 1111 1111 1100 * Plus 1:1111 1111 1111 1111 1111 1111 1111 1101 * (-3 binary 1111 1111 1111 1111 1111 1111 1111 1101) * The binary result is moved to the right one bit, because it is a negative number, so the highest bit of 1 * 1111 1111 1111 1111 1111 1111 1111 1110 * The result is a negative number * negation: 0000 0000 0000 0000 0000 0000 0000 0001 * Plus 1: 0000 0000 0000 0000 0000 0000 0000 0010 * Get 2, the result plus the minus sign is the decimal of the binary corresponding: -2*/System.out.println (-3 >> 1); /** >>> "unsigned" right-shift operator, * moves the object to the left of the operator to the right by the number of digits specified to the right of the operator. * Use 0 expansion mechanism, that is, whether the value of the positive or negative, the high 0. *-3 default int type 32 bit * Convert binary First: * Absolute value: 3 * absolute value binary: 0000 0000 0000 0000 0000 0000 0000 0011 * Reverse : 1111 1111 1111 1111 1111 1111 1111 1100 * Plus 1:1111 1111 1111 1111 1111 1111 1111 1101 * Move the binary result one bit to the right, Because it's unsigned, so. Maximum bit 0 * 0111 1111 1111 1111 1111 1111 1111 1110 * Result: 2147483646*/System.out.println (-3 >>> 1); }}
Java operators--with (&), non (~), or (|), XOR (^)