Operator in Java Program – 6

Bit-wise Operator Java Program

Operator is very important for all languages. Operator can calculate, check, assign, increase and decrease the value of variable. So operator is heart of java program. I give simple example of operator java program.

“X & Y”;

In this example X and Y are variable;

& (Bitwise) is an operator”

So we can easily understand the import of operator in java program language. In this blog we will discuss on Bitwise [ &, | , ^, >> , << , >>> ] operators.

Bit-wise operator 

&, | , ^, >> , << , >>>are bit-wise operator in java programming languages. These operators help for check binary numbers. We are familiar with this operator in C and Cpp. They are working same as C and Cpp.

 

Let’s see simple structure of bit-wise operator.

&, | and ^ Binary Chart

 

NoStatementAnd [ & ]Or [ | ]XOR [ ^ ]
11 , 1110
21, 0011
30, 1011
40, 0000

 

Let’s see simple example on this operator.

int X = 137;

int Y = 189;

1286432168421O/P
13710001001 
18910111101 
&10001001137
|10111101189
^0011010052

 

You can also bit-wise operator on YouTube.

 

 

 

>>, <<, >>> Operator in Java Program

This all are shifting operator, which are very useful in any binary calculation program.

Let’s see simple details of this operator.

Int X = 30;

Convert into Binary

1286432168421
00011110
X>>2 | Shift 2 Step Right all binary digit
00000111
Now New Number of X = 7

 

1286432168421
00011110
X<<2 | Shift 2 Step Left all binary digit
01111000
Now New Number of X = 120

 


Earn money online

1014total visits,10visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image