Program to demonstrate Bitwise exclusive OR operation in Java
Output of the program :
package com.hubberspot.examples; import java.util.Random; public class XORTest { public static void main(String[] args) { Random random = new Random(48); int number1 = random.nextInt(7); int number2 = random.nextInt(8); System.out.println("number1 : " + number1); System.out.println("number2 : " + number2); int result = number1 ^ number2; System.out.println("result : " + result); System.out.println(); System.out.println(number1 + " ^ "+number2 + " = " + result); System.out.println(); System.out.println("Printing result in binary format : "); System.out.println(Integer.toBinaryString(number1) + " ^ "+ Integer.toBinaryString(number2) + " = " + Integer.toBinaryString(result)); } }
Output of the program :