Comparison Logical and Bitwise Operator ( Java Part - 4 )

Java Comparison Operators

Comparison operators are used to compare two values:
OperatorNameExampleTry it
==Equal tox == yTry it »
!=Not equalx != yTry it »
>Greater thanx > yTry it »
<Less thanx < yTry it »
>=Greater than or equal tox >= yTry it »
<=Less than or equal tox <= yTry it »

Java Logical Operators

Logical operators are used to determine the logic between variables or values:
OperatorNameDescriptionExampleTry it
&& Logical andReturns true if both statements are truex < 5 &&  x < 10Try it »
|| Logical orReturns true if one of the statements is truex < 5 || x < 4Try it »
!Logical notReverse the result, returns false if the result is true!(x < 5 && x < 10)Try it »

Java Bitwise Operators

Bitwise operators are used to perform binary logic with the bits of an integer or long integer.
OperatorDescriptionExampleSame asResultDecimal
&AND - Sets each bit to 1 if both bits are 15 & 10101 & 00010001 1
|OR - Sets each bit to 1 if any of the two bits is 15 | 10101 | 00010101 5
~NOT - Inverts all the bits~ 5 ~01011010 10
^XOR - Sets each bit to 1 if only one of the two bits is 15 ^ 10101 ^ 00010100 4
<<Zero-fill left shift - Shift left by pushing zeroes in from the right and letting the leftmost bits fall off9 << 11001 << 100102
>>Signed right shift - Shift right by pushing copies of the leftmost bit in from the left and letting the rightmost bits fall off9 >> 11001 >> 1110012
>>>Zero-fill right shift - Shift right by pushing zeroes in from the left and letting the rightmost bits fall off9 >>> 11001 >>> 101004

Comments

Popular posts from this blog

Bubble Sort ( C & Python 3)

Something about me