Java bitwise AND Shift Operators (translated from Java tutorials)

Source: Internet
Author: User
Tags bitmask

From http://www.cnblogs.com/ggjucheng/archive/2012/12/15/2820012.html

English from http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

JavaProgramThe language provides bitwise AND shift operations for integer types. The operators discussed below are rarely used. The purpose of this chapter is clear to let you know the existence of these operators.

Bitwise complement operator "~" for one dollar It can be used for any integer to change each 0 to 1, and each 1 to 0. for example, byte A contains eight digits. If the bitwise mode is "00000000", this operator is used to change to "11111111 ".

Signed left shift operator"<", Move the bit to the left, with the symbol">", Move to the right. The bitwise mode is the operand of the left side, and the number of moving locations is the operand of the right side.

Unsigned right shift operator">>>"Move 0 to the leftmost, but for the signed left shift operator">", The leftmost digit depends on the corresponding symbol extension (NOTE: For positive numbers, the leftmost digit is 1, and the leftmost digit is 1 after the shifted symbol is left, the value of the unsigned left shift to the rightmost is 0 ).

By bit&Operator to perform a bitwise AND OPERATION

The bitwise ^ operator executes an bitwise XOR operation.

Bitwise | the operation executes a bitwise AND operation.

The following program,Bitdemo: outputs number "2" to standard output by bit and operation.

Class bitdemo {public static void main (string [] ARGs) {int bitmask = 0x000f; int val = 0x2222; // prints "2" system. out. println (Val & bitmask );}}

 

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.