Public classNewclass { Public voidbitwise operator () {/** 1 ~ Bitwise counter 1=~0 * 2 & bitwise with 0&1=0 1&1=1 0&0=0 * 3 | bitwise OR 0|1=1 1|1=1 0|0 =0 * 4 ^ bitwise XOR or 0^1=1 1^1=0 0^0=0 1^0=1 same 0, different 1*/ intx=53; intr=~x; System.out.println ("R=" +r);//-54, bitwise counter PLUS one inty=22;//10110System.out.println ("x&y=" + (x&y));// -System.out.println ("x|y=" + (x|y));// -System.out.println ("x^y=" + (x^y));// * /** Shift operator * << arithmetic left shift operator each left one bit, the right with 0, the left side of the number of digits lost * >> arithmetic right shift operator every right to move a bit, left with 0, the right of the extra Drop the number of digits * >>> logical right shift operator*/System.out.println ("4<<2=" + (4<<2));//0000 0100 (4) shift left two bits 0001 0000 (+)System.out.println ("4<<3=" + (4<<3));// +System.out.println ("12>>2=" + (12>>2));//0000 1100 (12) Shift right two bits to 0000 0011 (3)System.out.println (" -12>>2=" + ( -12>>2));//-3System.out.println ("12>>>2=" + (12>>>2)); System.out.println (" -12>>>2=" + ( -12>>>2)); /** Bitwise OPERATIONS Priority: ~ << >> >>> & ^*/ } Public voidPriorityofbitoperator () {inta=-67,b=116,c=78; //a=10111101,b=01110100,c=01001110 intd=~a|b&C; inte=~c>>2& (a|~b); intf=a^b&C; System.out.println ("D=" +d); System.out.println ("E=" +e); System.out.println ("F" +f); } Public voidassignment operator () {//Ordinary assignment Operators byteB=123; intI=b; inta=222; intj=i+A; //Extended Assignment Operators//+ = = *=/=%= &= |= ^= >>= <<= >>>=I+=1;//i=i+1 124i+=100;//i=i+100 224i-=10;//i=i-10 214i*=2;//i=i*2 428System.out.println ("i=" +i);//428 } Public voidConditional operator (intresults) { //Three mesh operator//logical expression? Expression 1: Expression 2//int score =0;String result; Result= Score >=60? " Passed ":" did not pass "; System.out.println ("Score:" +result); } Public Static voidMain (string[] args) {newclass oe=NewNewclass (); OE. Bitwise operators (); Oe.priorityofbitoperator (); //OE. Calling methodOE. Assignment operator (); OE. Conditional operator (80); } }
Java bits, assignments, conditional operators, etc.