package org.kodejava.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
Latest posts by Wayan (see all)
- How do I create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023