Java Reference
In-Depth Information
The unsigned right shift operator ( >>> ) works the same as the signed right shift operator (>>), except for one
difference. It always fills the higher order bits with zero. The result of 13 >>> 4 is zero whereas the result of -13 >>> 4
is 268435455 , as shown below. There is no unsigned left shift operator.
13 00000000 00000000 00000000 00001101
13 >>> 4 00000000 00000000 00000000 00000000 1101
-13 11111111 11111111 11111111 11110011
-13 >>> 4 00001111 11111111 11111111 11111111 0011
A compound bitwise assignment operator is used in the following form:
operand1 op= operand2
Here, op is one of the bitwise operators of & , | , ^ , << , >> , and >>>. operand1 and operand2 are of primitive integral
data type where operand1 must be a variable. The above expression is equivalent to the following expression:
operand1 = (Type of operand1) (operand1 op operand2)
Assuming that there are two int variables, i and j , Table 4-8 lists the equivalent expression for compound
bitwise assignment operators.
Table 4-8. List of Compound Bitwise Assignment Operators
Expression
is equivalent to
i &= j
i = i & j
i |= j
i = i | j
i ^= j
i = i ^ j
i <<= j
i = i << j
i >>= j
i = i >> j
i >>>= j
i = i >>> j
Summary
An operator is a symbol that is used to perform some type of computation on its operands. Java contains a rich set of
operators. Operators are categorized as unary, binary, or ternary based on the number of operands they take. They are
categorized as arithmetic, relational, logical, etc. based on the operation they perform on their operands.
An operator is called overloaded if it can be used in multiple contexts to perform different types of computations.
Java contains a + operator that is overloaded. It is used as an arithmetic addition operator as well as a string
concatenation operator. Unlike C++, Java does not let developers overload operators in programs.
 
Search WWH ::




Custom Search