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

How to use the java shift character

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 "how to use java shift character". In daily operation, I believe many people have doubts about how to use java shift character. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use java shift character". Next, please follow the editor to study!

Overview

There are three main types of java shifters:

> > left shift operator > > 3);}}

Operator name

The results are as follows:

16-81-1536870911

First of all, we need to know that in computer systems, numerical values are generally represented by complements, mainly because the use of complements can unify symbol bits and other bits, and we need to convert all the above values into complements.

Left shift operator

1 3

According to the above process, I will directly simplify the     source code as follows: 0000 0000 0000 1000 1 * 2 ^ 3 = 8     inverse code: 0000 0000 0000 000 000     complement: 0000 0000 0000 000 1000

The result after operation: 0000 0000 0000 0001 0001 * 2 ^ 0 = 1 (red is truncated, blue is the newly added symbol bit, and filled with the original symbol bit)

-8 > > 3

According to the above process, I will directly simplify the     source code to: 1000 0000 0000 0000 1000-1 * 2 ^ 3 = 8     inverse code: 1111 1111 1111 0111     complement: 1111 1111 1111 11

The result after calculation: 1111 1111 1111 (red is truncated, blue is the newly added symbol bit, and filled with the original symbol bit) into the source code: 1000 0000 0000000 0000000 00000001-1 * 2 ^ 0 =-1

Summary

Like the left shift operator, it can be concluded that the shift of the right shift operator by a few bits is the power of dividing the Operand by 2.

Unsigned right shift operator

-8 > > 3

According to the above process, I will directly simplify the     source code to: 1000 0000 0000 0000 1000-1 * 2 ^ 3 = 8     inverse code: 1111 1111 1111 0111     complement: 1111 1111 1111 11

The result after operation: 0001 1111 1111 1111 (red is truncated, pay attention to the yellow part, add 0 in the unsigned right shift operation bit)

At this point, the value will be very large, so you will get the results in the program.

Supplement

If the operation type is lower than the int type, such as byte,char, etc., convert it to the int type before shifting.

For int type shift, if the number of bits moved exceeds 32 bits, let the number of bits take the remainder of 32, and then run it, that is, a > > 33 = = a > > 1 a > > 32 = = a

Similarly, if the number of moving bits is more than 64 for long-type shifts, the number of moving bits also needs to be processed.

Code supplement

The code for the supplementary content is not explained in detail, and the code and operation results are as follows, and the basic process is similar to the above.

Code:

Public class BitOperatorTest {public static void main (String [] args) {System.out.println ((char) 4 > 2);}}

Running result:

646464303303

At this point, the study on "how to use the java shift character" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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