JAVA program to use Bitwise Operators
This JAVA Program is to use Bitwise Operators.
Logic
We have take two variables a and b and then we have just performed operations on both variables using bitwise operators.
Program
import java.util.*; class bitwiseOp { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the first no"); int a = sc.nextInt(); System.out.println("Enter the second no"); int b = sc.nextInt(); System.out.println("AND of "+a+" and "+b+" = "+(a&b)); System.out.println("OR of "+a+" and "+b+" = "+(a|b)); System.out.println("XOR of "+a+" and "+b+" = "+(a^b)); System.out.println(a+"<< 2 = "+(a<<2)); System.out.println(b+"<< 2 = "+(b<<2)); System.out.println(a+">> 2 = "+(a>>2)); System.out.println(a+">> 2 = "+(b>>2)); System.out.println("~"+a+" = "+(~a)); System.out.println("~"+b+" = "+(~b)); } }