Hello Friends!!!
Today we are going to learn Bitwise Operator, in the previous article we have learned Assignment and Arithmetic operator.
Arithmetic and assignment operators work with operand (variables & values) directly, bitwise operators work on bits of int, long, short, char, byte datatype operands. Let's understand how many bitwise operators are there and how do bitwise operators work?
Today we are going to learn Bitwise Operator, in the previous article we have learned Assignment and Arithmetic operator.
Arithmetic and assignment operators work with operand (variables & values) directly, bitwise operators work on bits of int, long, short, char, byte datatype operands. Let's understand how many bitwise operators are there and how do bitwise operators work?
Bitwise Operators
|
||
~
|
Not (Unary)
|
~a
|
&
|
And
|
a&b
|
|
|
Or
|
a|b
|
^
|
Exclusive Or
|
a^b
|
>>
|
Shift Right
|
a>>b
|
>>>
|
Shift Right
with zero fill
|
a>>>b
|
<<
|
Shift Left
|
a<<b
|
&=
|
And
Assignment
|
a&=b
|
|=
|
Or
Assignment
|
a|=b
|
^=
|
Ex-Or
Assignment
|
a^=b
|
>>=
|
Shift Right
Assignment
|
a>>=b
|
>>>=
|
Shift Right
Assignment with zero fill
|
a>>>=b
|
<<=
|
Shift Left
Assignment
|
a<<=b
|
Fig. Bitwise Operators
How do bitwise operators work?
Fig. Bitwise Operator with a bit values |
Let's make it easy to use and work let's take two variables A=5 and B=2.
Now convert values of A & B to binary so, A=0000 0101 and B=0000 0010 and perform some operations based on the above figure.
Check the above figure for and, or, ex-or, and for negation, Java performs two's complement. Try to calculate the above operations and check the 👇 example and get the answer(output).
That's it for this article, in the next article we will learn more operators of Java. Till then
Happy Coding...☺😊
Fig. Bitwise Operations |
That's it for this article, in the next article we will learn more operators of Java. Till then
Happy Coding...☺😊
No comments:
Post a Comment