~ the NOT Operator (非运算符) | the OR Operator (或运算符) & the AND Operator (与运算符) ^ the XOR Operator (异或运算符) ~ the NOT Operator(非运算符) 以下是《Thinking in java》中的描述: The bitwise NOT (~, also called the ones complement operator) is a unary operator; it takes...
位操作符允许我们操作一个基本数据类型中的整数型值的单个“比特(bit)”,即二进制位。 位操作符会对两个参数对应的位执行布尔代数运算,并终生成一个结果。 位操作符来源于 C 语言面向底层的操作,那时我们经常需要直接操纵硬件,设置硬件寄存 器内的二进制位。Java 的设计初衷是嵌入电视机顶盒内,所以这种低级操作...
Also, logical operators always evaluate the first boolean expression and, depending on its result and the operator used, may or may not evaluate the second. On the other hand, bitwise operators always evaluate both operands. Finally, logical operators are used in making decisions based on multi...
The bitwise ^ operator performs a bitwise exclusive OR operation. The bitwise | operator performs a bitwise inclusive OR operation. The following program, BitDemo, uses the bitwise AND operator to print the number "2" to standard output. class BitDemo { public static void main(String[] args)...
| Bitwise OR ^ Bitwise XOR ~ Bitwise complement Shift left >> Shift right Bitwise AND Operator & The output of bitwise AND is 1 if the corresponding bits of two operands is 1. If either bit of an operand is 0, the result of corresponding bit is evaluated to 0. In C Programming, the...
sets: a union operation dicts: an update operation counters: a union (of multisets) operation numbers: a bitwise OR, binary operation In most cases, it is related to the | operator. See examples below. 1 Sets2 Dictionaries3 Counters4 Numbers ...
2. Arithmetic Right Shift >> or Signed Extension. 算术右移>>或带符号的扩展名 The arithmetic right shift>>or signed right shift preserves the sign (positive or negative numbers) after bits shift. This>>operator fills all the left empty positions with the original most significant bit (the fir...
This operator combines its two integer operands by performing a Boolean OR operation on their individual bits. The result has a bit set if the corresponding bit is set in either or both of the operands. It has a zero bit only where both corresponding operand bits are zero. For example: ...
OperatorNameDescription &ANDSets each bit to 1 if both bits are 1 |ORSets each bit to 1 if one of two bits is 1 ^XORSets each bit to 1 if only one of two bits is 1 ~NOTInverts all the bits <<Zero fill left shiftShifts left by pushing zeros in from the right and let the ...
The &^ operator is bit clear (AND NOT): in the expression z = x &^ y, each bit of z is 0 if the corresponding bit of y is 1; otherwise it equals the corresponding bit of x. 即z = x &^ y运算相当于先把y取反(针对y的每个...