How do I do bitwise exclusive OR operation?

Category: fundamental, viewed: 8741 time(s).
package org.kodejava.example.lang;

public class XORDemo {
    public static void main(String[] args) {
        int numberA = 16;
        int numberB = 32;

        //
        // Operator ^ is used for doing bitwise exclusive OR operation
        //
        int result = numberA ^ numberB;

        System.out.println(numberA + " ^ " + numberB + " = " + result);

        //
        // Print the result in binary format
        //
        System.out.println(Integer.toBinaryString(numberA) +
                " ^ " + Integer.toBinaryString(numberB) +
                " = " + Integer.toBinaryString(result));
    }
}

The program prints the following output:

16 ^ 32 = 48
10000 ^ 100000 = 110000
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats