In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail the "case analysis of Java bit operation", with detailed content, clear steps and proper handling of details. I hope that this "case analysis of Java bit operation" article can help you solve your doubts.
First, the classification and presentation effect of bit operation
Java bit operation can be divided into left shift and right shift, in which right shift and unsigned right shift.
Java is only for integer displacement and can be divided into int system and long system. The int system includes (byte, short, int, char), and the long system only contains long. When bit operation is carried out in int system, except for int type, it will be converted to int before operation. .
Unsigned right shift means that when you move to the right, the left offset is 0.
In general, moving right and left is often used to multiply by 2n or divide by 2n. (remove to the right by 2n, move to the left multiplied by 2n)
Int i1 = 4; int R1 = i1 > > 2; / / divided by 2 ^ 2int R2 = i1 1 0111 1111 (inverse) = > 1 1000 0000 (supplement) = > 1000 0000 (supplement)
(looking at some explanations, the complement of-128is 1000 0000. If you don't understand, you can skip it first. )
Moving to the left means that the complement moves to the left, the one vacated on the right is filled with 0, the one on the right is moved to the right, and the one vacated on the left is filled with the symbol bit. Move to the right unsigned, and the left vacant position is filled by 0. The following is an example of specific code (int is 32-bit):
Positive number:
Int i1 = 4; / 0000 0000 0000 0100int R1 = i1 > > 2; / expectation 0000 0000 0000 0000000 00000001 = 1int R2 = i1 > 2; / / expectation: 1111 1111 1111 = i2 > > 1; / / expectation: 0111 1111 1111 1111 1110 = 2147483646System.out.println (rx); / / actual: 2147483646System.out.println (r3); / actual:-1System.out.println (R4) / / actual:-16
Rx records the result of unsigned right shift, and after moving, the left padding is filled with 0, so the result becomes 2147483646.
III. Boundary value testing
The range of int type is [- 2147483648, 2147483647]. The upper and lower bounds are tested below:
/ / Boundary value test: int imax = Integer.MAX_VALUE; / / 21 "4748" 3647 = 0111111111111111111111111111111111111111 (2 ^ 31-1) int R5 = imax > > 2; / 000111111111111111111111111111111111111111 = (2 ^ 30-1) = 5_3687_0911System.out.println (R5); / / actual: 5_3687_0911int R6 = max
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.