Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What shift operators are there in Java

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the relevant knowledge of which shift operators are in Java, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this Java article on which shift operators are available. Let's take a look.

1. Left shift operator

The left shift operator is represented by "> >". It moves the object on the left side of the operator to the right by the specified number of digits to the right of the operator, and fills in 0 in the high position. in fact, moving n bits to the right is equivalent to dividing the n power of 2.

Public class test {public static void main (String [] args) {int aq16; int bread2; System.out.println ("the result of a shift is" + (a > b));}}

Output: 4

Analyze the above code: the binary of 16 is 00010000, and when it moves 2 bits to the right, it becomes 00000100, or 4. If you analyze it from another point of view, it moves 2 bits to the right, which is actually divided by 2 to the power of 2, and the result is still 4.

3. Signed right shift operator

The signed right shift operator is represented by "> >", which moves the Operand on the left side of the operator to the right by the specified number of digits. If it is a positive number, zero in the high position, and 1 in the high position, if it is a negative number.

Public class test {public static void main (String [] args) {int aplomb 16; int cymbal color 16; int bau2; int dong2; System.out.println ("a shift result:" a > b); System.out.println ("c shift result:" (c > > d));}}

Output: 4 and-4

Analyze the above code: the value of an is 16 to binary is 00010000, let it move two bits to the right to 00000100, that is, 4, the value of c is-16 to binary is 11101111, let it move one bit to the right to 11111011 or-4

This is the end of the article on "what shift operators are in Java?" Thank you for reading! I believe you all have a certain understanding of "what shift operators are in Java". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report