/*bitwise operator Operator: an example of the operation illustrates <<: Move left 3<<2=12--->3*2*2=1 2 >>: Right shift 3>>2=1---->3/2=1>>>: Unsigned Right Shift 3>>>2= 1--->3/2=1&: with operations 6 & 3=2|: or OP 6 | 3=7^: XOR operation 6^3=5~: Anti-code ~6=-7*///shift left: The left shift is multiplied by the power of 2. The number of moves is several times power. //the use of left shift: for example, to do 3*4 in a computer,//The 011*100 is multiplied by binary in the computer, but//It is now possible to use bitwise arithmetic (left shift),//That is, to move 3 left 2 bits to get the result, so that the operation is very fast,//The disadvantage is that you can only operate a multiple of 2, in the development process if you want to operate 2//multiples or 2 of the recurses, the bitwise operation can be implemented. //Move right: Shift right is the power operation divided by 2. The number of moves is several times power. /*when you move to the right, the original highest bit is what the empty space complements (preserving the original symbolism). *///unsigned Right Shift: not used for division operations. /*no matter what the original top bit is, the vacancy is 0. The use is: to get the value of a segment in the binary such as: A binary is: 00000000 00111100 00000000 00110110 If the three-bit three-bit gets its value (one-time right-shift unsigned three-bit), The first right-shift three-bit gets (110: The result is 6), then the three bits are removed, the next three bits become the lowest three bits, and then the three bits are obtained ... The final result is the octal number corresponding to this binary. (Get four bits, which is the hexadecimal corresponding to the binary) The summary is: When doing the operation about 2, consider the left shift and the right shift operation. In binary bitwise operations, the unsigned right shift is used. *///& Operations:/*In the binary in the & operation process, only 1 o'clock, the result is 1, Otherwise 0. The use is: in obtaining a certain binary of a certain number of times, such as: A binary is 00101011, to obtain the last three bits can be used three 1 and the last three binary as a sentence: To obtain a valid bit in binary 10010101100000111-----------00000011- -----The last three bits are bits when you want to get the second three bit, you can first move this binary unsigned right three bits in and 00000111*///|: Arithmetic/*6|3= 110|001----111--->7 (decimal)*///^: Arithmetic/*6^3=5 ^011----101--->5 ^011------->6 namely 6^3^3 = 6; A number or another number, or the result is the original number. (for encryption)*///~: Negation operation:/*~6=-7: The calculation is as follows: 6--->00000110:--->11111001 because it is stored in the form of complement in the computer. So to think of 11111001 as a complement, now turn this complement into the original code (first into the inverse code: minus 1 on the line--->11111000, and then into the original code, the highest bit is the sign bit, the other is the bitwise take the inverse---> 10000111 re-converted to decimal-7) such as 6 reverse and add 1 to 6*///the practice of bitwise operators:/*1, how to calculate the most efficient 2*8 by left to the operation: 2<<<3--->2*8 = 16;//system.out.println (2<<3);---> The result is 162, Swaps the values of two integer variables (no third-party variables are required) int a = 3,b = 7; The method of passing a third-party variable is as follows: int temp; temp = A; A = b; b = temp; (not through third-party variables) and the form. There is a disadvantage that two data is large and may exceed the int range. This method is not very good a = a+b; A = 3+7; b = a A; b = 3+7-7; b = 3; A = a=b; A = 3+7-3; A = 7; (without third-party variables) is solved by bitwise operations. A = A^b; A = 3^7; b = a^b; b = 3^7^7; --->b = 3; A = A^b; A = 3^7^3; --->a = 7;*///ternary Operator: Format: (conditional expression)? Expression 1: expression 2;//int x = 2,y; //y = x>1?100:200; //demand: There are three numbers, you want to know which is the biggest one? /*int a = 2,b=3,c =4,max; if (a>b) max = A; if (max<b) max = b; System.out.println ("max=" +max); */classoperatedemo1{ Public Static voidMain (string[] args) {intA=3,b=40,c=5; intMax; if(a>b) Max=A; ElseMax=b; if(max<c) Max=C; ElseMax=b; System.out.println ("Max=" +max); }}
"JAVA---day03---operator"