shift n is the equivalent of multiplying by 2 of the n-th square4) Calculation process:Example: 3 1) Convert 3 to binary number 0000 0000 0000 0000 0000 0000 0000 0011,2) Move the digit high (left) to two 0, and the other numbers are shifted to the left by 2 bits,3) Two vacancies in the low (right) 0. The resulting result is 0000 0000 0000 0000 0000 0000 0000 1100,Conversion to decimal is 12.The number of bits moved exceeds the maximum number of digi
shift n is the equivalent of multiplying by 2 of the n-th square4) Calculation process:Example: 3 1) Convert 3 to binary number 0000 0000 0000 0000 0000 0000 0000 0011,2) Move the digit high (left) to two 0, and the other numbers are shifted to the left by 2 bits,3) Two vacancies in the low (right) 0. The resulting result is 0000 0000 0000 0000 0000 0000 0000 1100,Conversion to decimal is 12.The number of bits moved exceeds the maximum number of digi
The arithmetic object that the shift operator faces is also the binary "bit". You can use them individually to handle integer types (one of the main types). The left shift operator (If Char,byte or short are shifted, they are automatically converted to an int before the shift occurs. Only 5 lows to the right are used. This prevents us from moving an unrealistic n
Http://soft.chinabyte.com/database/195/11553695.shtmlThe Java shift operators are all about these three kinds of:1. Left shift operatorThe left shift operator 1) Its general format is as follows:Value NUM Specifies the number of bits to shift the value to move.Left-
The following code:public class Example027 {public static void main (string[] args) {int i = 0;while ( -1 Result Description: put the above program into eclipse, and the output line will prompt "unreachable code". That is, the while loop is a dead loop and cannot be exited. Results Analysis: Java uses a 2 complement binary arithmetic operation, so that 1 of any signed integer type (byte, short, int, or lon
, or 1 in the high position if the value is negative. Java also adds a "unsigned" right shift operator (>>>) that uses "0 extensions": Inserts 0 at the high level, whether positive or negative. This operator is not in C or C. If Char,byte or short are shifted, they are automatically converted to an int before the shift occurs. The only 5 lows on the right side
There are three kinds of shift operators in Java>>: Right shift operator, NUM >> 1, equivalent num divided by 2>>>: Unsigned Right shift, ignore sign bit, empty 0
1. Left shift operator
The left shift operator 1) Its g
Java shift operation (Collection + correction + layout)
This collection comes from network collection. It is my arrangement, correction, and layout to provide you with a comprehensive explanation of the knowledge. It may be difficult to arrange it in some places.========================================================== ========================================================== ======
There are three kinds of shift operators in Java>>: Right shift operator, NUM >> 1, equivalent num divided by 2>>>: Unsigned Right shift, ignore sign bit, empty 01. Left shift operatorThe left shift operator 1) Its general format
replaced by the int type, so it occupies 32 bits; If you define a byte array of type Boolean, the JVM compiles it to a byte array type, which takes up 8 bits. In fact, here also listen to doubts, why a Boolean can occupy 8, one will occupy 32? Personal understanding of the feeling is that when the real Boolean, should be only 1 bits, not 0 is 1, but the specific compile time other occupancy may be used for other purposes. OK, next, let's look at the problem with the
The Java shift operators are all about these three kinds of:1. Left shift operatorThe left shift operator 1) Its general format is as follows:value num Specifies the number of bits to shift the value to move. left-shift rule only
result of a shift is: 8The result of the x shift is: 4Shift results for M: 4Shift results for P: 4Two. Assignment operatorsAssignment is assigning a value to a variable, and the assignment operator acts as the assignment, in fact, the simplest assignment operator is "=".There are, of course, many other assignment operators besides "=". There are "+ =", "-=", "*=", "/=", "%=", ">>=", ">>>=", "public
Java Shift Operators
Java shift operators are essentially three types:
1. Left Shift OperatorLeft shift operator
1) its general format is as follows:
Value Num specifies the number of digits in which the value to be shifted i
lows on the right are used at this point to prevent moving more than the number of bits in the Long value. But you may also experience a problem when you make an unsigned right shift. If you perform a right shift operation on a byte or a short value, may not get the correct result (Java 1.0 and Java 1.1 are particul
The Java shift operators are all about these three kinds of:1 . Left shift operator left shift operator 2) The arithmetic rules move all numbers to the left of the corresponding digits in binary form, the high position is shifted out (discarded), and the low vacancy is 0. When the left-hand operand is of type int, the
Keep in mind that all the moving digits are in the complement, so first convert the decimal integer to the complement and then the shift operation.Shift operation also pay attention to the type of constraints, such as int, moving range is 0-31 bits, so the complement can only see the last five digits, this is a valid number, long moving range is 0-63, so the complement can only see the last six bits.move the operator right .Left
Java tutorial translation Sequence Java Introduction Build a JSE development environment-install JDK and eclipse Language basics Java Hello World Program Analysis Variable Java Variables Java Native type Conversion of Java
The shift operator is oriented to an Operation object that is also a binary "bit". You can use them individually to handle integer types (one of the main types). The left shift operator ( If Char,byte or short are shifted, they are automatically converted to an int before the shift occurs. Only 5 lows to the right are used. This prevents us from moving an unreal
There are three kinds of shift operators in Java
>>: Right shift operator, NUM >> 1, equivalent to num divided by 2
>>>: Unsigned right shift, ignoring symbol bit, vacancy is 0
Let's take a look at how these shift operations are used
Copy Code code as follows:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.