Java bits, assignments, conditional operators, etc.

Source: Internet
Author: User
Tags bitwise bitwise operators

 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.