BITWISE OPERATOR

BITWISE OPERATOR
package com.company;

public class Main {

public static void main(String[] args) {
//AND operator
int x=10,y=6,z;
z=x&y;//both bits should be 1
/*
x y x&y
0 0 0
0 1 0
1 0 0
1 1 1
*/
System.out.println("z=x&y : "+z);
//OR bitwise operator
z=x|y;//one of bits should be 1
/*
x y x|y
0 0 0
0 1 1
1 0 1
1 1 1
*/
System.out.println("z=x|y : "+z);
//XOR bitwise operator
z=x^y;//only one bits should be 1
/*
x y x^y
0 0 0
0 1 0
1 0 0
1 1 0
*/
System.out.println("z=x^y : "+z);

/*LEFT SHIFT operator * It will double the number by moving 1 place
* Automatically filed vacant place with zero
* n*2^k || where k is how many place move


x = 00001010
///////
000010100

*/
z=x<<1;
System.out.println("Left shift by one place : " + z);
/*RIGHT SHIFT operator * It will HALF the number by moving 1 place
* Automatically filed vacant place with zero
* N/2^K || where k is how many place move


x = 00001010
\\\\\\\
0000101

*/
z=x>>2;
System.out.println("Right shift by one place : " + z);

System.out.println("NOt operator : Inverse the binary number ");
int a = 10,c=50;
int f = a ^ c;
System.out.println(f);

}
}

OUPUT:-

z=x&y : 2
z=x|y : 14
z=x^y : 12
Left shift by one place : 20
Right shift by one place : 2
NOt operator : Inverse the binary number 
56

Process finished with exit code 0

Comments

Popular posts from this blog

Phone Dictionary Application in c

swapping of two number in java with algorithm.

Dollar to Rupee and Rupee to Dollar app .