Bitwise operations and SHIFT operations in Java

Source: Internet
Author: User

To facilitate the operation of the BITS, Java provides us with the following four bits operators:

& Bitwise AND

| Bitwise OR

^ Bitwise XOR OR

~ Bitwise REVERSE

There are three shift operators in Java:

Left shift:<< discard the highest bit, 0 fill the lowest bit; num << 1, equal to num multiplied by 2

Sign right shift:>> symbol bit unchanged, left with sign bit on the other side; Num >> 1, which is equivalent to num divided by 2

Unsigned right shift:>>> ignores the sign bit, and the empty space is padded with 0;

eg

Number x x<<2 x>>2 x>>>2

17 00010001 00¦01000100 00000100¦01 00000100¦01

-17 11101111 11¦10111100 11111011¦11 00111011¦11

Bitwise operations and SHIFT operations in Java

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.