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/03 Report--
This article introduces the relevant knowledge of "mobile bit operation example explanation in java". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
1. concept
Right shift operator, right shift is preceded by 1 or 0, num>> 1, equivalent to num divided by 2
>>> No sign right shift, yes in front of 0, ignore the sign bit, empty spaces are filled with 0
In addition, whether it is left or right shift 32 bits, equivalent to no move, or the original value.
In fact, when the Java virtual machine executes this code, it executes as follows:
5>>(n%32)---> Results
You have n = 32 here; so 5>> 32 is the result of 5>>(32%32)--> 5>> 0;
2. test code
public class Test{public Test(){System.out.println ("=========== Arithmetic Shift Right>======"); int i = 0xC 000000; System. out. println ("before shift: i ="+ i +"="+ Integer. toBinaryString (i)+"(B)"); i = i>> 28; System.out.println ("after shift: i ="+ i +"="+ Integer. toBinaryString (i)+"(B)"); System. out. println ("---------------------------------"); int j=0x0C000000; System.out.println ("before shift: j ="+ j +"="+ Integer. toBinaryString (j)+"(B)"); j = j>> 24; System. out. println ("after shift: j ="+ j +"="+ Integer. toBinaryString (j)+"(B)"); System. out. println ("\n "); System. out. println ("================= logical shift right>>======="); int m = 0xC000000; System. printout.("before shift: m ="+ m +"="+ Integer. toBinaryString (m)+"(B)"); m = m>> 28; System. out. println ("after shift: m ="+ m +"="+ Integer. toBinaryString (m)+"(B)"); System. out. println ("---------------------------------"); int n=0x0C000000; System.out.println ("before shift: n ="+ n +"="+ Integer. toBinaryString (n)+"(B)"); n = n>> 24; System. out. println ("after shift: n ="+ n +"="+ Integer. toBinaryString (n)+"(B)"); System. out. println ("\n "); System. out. println ("====================="); int a = 0xCC00000; System. printout.("before shift: a ="+ a +"="+ Integer. toBinaryString (a)+"(B)"); System. out. println ("Arithmetic shift right 32: a ="+(a>> 32)+"="+ Integer. toBinaryString (a>> 32)+"(B)"); System.out.println ("logical shift right 32: a ="+(a>>> 32)+"="+ Integer. toBinaryString (a>>> 32)+"(B)"); System.out.println ("Arithmetic shift right 64: a ="+(a>> 64)+"="+ Integer. toBinaryString (a>> 64)+"(B)"); System.out.println ("logical shift right 64: a ="+(a>>> 64)+"="+ Integer. toBinaryString (a>>> 64)+"(B)");} public static void main (String [] args){new Test ();}}
Run Results:
====================================
Before shift: i =-1073741824 = 110000000000000000000000 (B)
After shift: i =-4 = 11111111111111111111111111100 (B)
Before shift: j = 201326592 = 1100000000000000000 (B)
After shift: j = 12 = 1100 (B)
==============
Before shift: m =-1073741824 = 11000000000000000000000 (B)
After shift: m = 12 = 1100 (B)
Before shift: n = 201326592 = 110000000000000000 (B)
After shift: n = 12 = 1100 (B)
=====================
Before shift: a =-872415232 = 110011000000000000000 (B)
Arithmetic right shift 32: a =-872415232 = 1100110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Logic shift right 32: a =-872415232 = 1100110000000000000000000 (B)
Arithmetic right shift 64: a =-872415232 = 1100110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Logic shift right 64: a =-872415232 = 110011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
3. Why isn't there an unsigned left shift?
You can think about this problem and you should be able to figure it out. (Note: None means none exists.)
"Java mobile bit operation example explanation" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.