Pin It

A simple Java program demonstrating Bitwise exclusive OR operation

Program to demonstrate Bitwise exclusive OR operation in Java

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 : 


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot