In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "what is the use of Java bit operator", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "what is the use of Java bit operator" this article.
Commonly used operators
In the Java language, officials provide us with a wealth of operations, but the common ones seem to be arithmetic operators, such as addition, subtraction, multiplication, division, remainder, and so on. There are relational operators greater than, less than, equal to, not equal to, and so on. Or the logical operator & &, | |,! As for bit operators, there are not many practical ones. First of all, it can help you to understand the underlying principles of the computer, and secondly, it can give you a slight advantage in the interview. there are some people who can't tell the difference between logical operators and bit operators, such as & &, | and |, what the difference is, anyway, I was a little confused at the beginning, so this article can be regarded as a solution for myself.
Bit operator
Bit operator, from the literal meaning, we can know that bit operation is not difficult, but we do not often use it, coupled with the confusion with logical operators, so it is easy to make people confused. Here we mainly explain &, |, ^, ~, >, >. Among them, ~ and > is more complex.
&, |, ^ operators
& is bitwise and, | is bitwise or, ^ is bitwise XOR, these three bit operations are relatively simple. The screenshot of the program below should be clear at a glance.
~ operator
First of all, we should be clear that numbers are stored in binary in the computer, exactly in the form of binary complement, and the numbers we see are generally displayed in decimal form in the form of binary source code. the original code, inverse code and complement code of positive numbers are themselves, while the inverse codes of negative numbers are the same symbol bits, and the rest are inverted. The complement of a negative number is its inverse code + 1. Here through simple examples to explain the original code, anti-code, complement.
Let's take the number 5 as an example, which is explained by one byte. The original code of 5 is 00000101, the inverse code is also 00000101, and the complement is still 00000101, in which the complement is stored in the computer. If the reverse of 5 is what, 5 after the original code is reversed is 11111010, remind: (the highest bit 1 means the number is negative, 0 means the number is positive). But what is stored in the computer is a complement, and as mentioned above, the complement of a negative number is an inverse plus 1. The inverse code is 10000101 (the negative code does not change the symbol bit). The first 1 here is the symbol, plus 1, the complement code 10000110, which is what we see as-6. Description: the reverse is to change all 1 into 0, all 0 into 1, and the inverse code is that except for the symbol bit, the other 1 becomes 0 and 0 becomes 1.
Operator
To put it simply, 1 is divided by 2, where the positive right shift is the precomplement 0 and the negative right shift is the precomplement 1. The operation here is faster than * /. When you look at the original JDK code, you should have seen these symbols.
> operator
This is unsigned right shift, what is unsigned right? first of all, let's talk about what signed right shift, signed right shift, that is, when the number is positive, move right forward to complement 0, when the number is negative, move right forward to fill 1. The unsigned shift to the right, whether positive or negative, is a prefix of 0. Here we take-5 as an example to explain. By moving to the right unsigned, a negative number becomes a positive number.
Yes
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.