In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces Java how to achieve bit operation, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Public class Operation5 {public static void main (String [] args) {/ / bit operation / * includes: and &, or |, reverse ~, XOR ^ move to the signed left Unsigned right shift > 1. & that is, the binary bit is 1 if all are 1. Otherwise, it is 0 2. | it is 0 if all binary bits are 0, otherwise it is 1 3. ~ that is, the binary bit becomes 1 if it is 0, otherwise it becomes 0 if it is 1. 4. ^ is 0 when both binary bits are equal at the same time, otherwise it is 1 5. Is to move the binary bit by bit to the right, adding n symbol bits in front of it, dividing the equivalent by 2; 6. > is to move the binary bit by bit to the right, followed by n bits 0 * / byte a = 1; / / binary 00000001 byte b = 8 / / binary 00001000 byte c = 127 byte byte d =-127 System.out.println System.out.println / binary 10000001 System.out.println (a & b); / / result 00000000 System.out.println (a | b); / / result 00001001 2 ^ 3 + 2 ^ 0 = 9 System.out.println (~ a) / / result 11111110 complement converted to original code = 10000001 color 1-1 color color 2 System.out.println (a ^ b); / / result 00001001 = 9; System.out.println (a 1); / / result 00000000 = 0 System.out.println (c > > 1); / / result 00111111 = 63 System.out.println (d > > 1) / / result 11000000 complement original code = 10111111 color 63-1 color color 64 System.out.println (d > 1); / / result 01000000 original code / * Note: 1. The first binary bit in computer storage indicates that the symbol bit 1 represents a negative number and 0 represents a positive number 2. When the computer is stored in the form of complement, the complement of positive number is the same as the original code, and the complement of negative number is obtained by removing the first symbol bit and then + 1. 3. If the complement code is converted to the original code, the first bit will be removed and the inverse calculation result will be-1. 4. System.out.println does not have System.out.println (byte b) method, the computer first automatically converts byte into int, and then on the move * /}} Thank you for reading this article carefully. I hope the article "how to achieve bit Operation in Java" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.