truth table
a = 0011
b = 0101
a ^ b = 0110

properties

(a ^ b) == (b ^ a)
proof
a = 0011
b = 0101
a ^ b = 0110
b ^ a = 0110

(a ^ 0) == a
proof
a = 01
0 = 00
a ^ 0 = 01

(a ^ a) == 0
proof
a = 01
a ^ a = 00

((a ^ b) ^ c) == (a ^ (b ^ c))
proof
a = 00001111
b = 00110011
c = 01010101
a ^ b = 00111100
(a ^ b) ^ c = 01101001
b ^ c = 01100110
a ^ (b ^ c) = 01101001


source code

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class XorTest {
@Test
public void test() {
{
System.out.format("truth table\n");
int a = 0 * 8 + 0 * 4 + 1 * 2 + 1 * 1;
int b = 0 * 8 + 1 * 4 + 0 * 2 + 1 * 1;
System.out.format("a = %s\n", toBinaryString(a).substring(32 - 4, 32));
System.out.format("b = %s\n", toBinaryString(b).substring(32 - 4, 32));
System.out.format("a ^ b = %s\n", toBinaryString(a ^ b).substring(32 - 4, 32));
System.out.format("\n");
}
System.out.format("properties\n");
System.out.format("\n");
{
System.out.format("(a ^ b) == (b ^ a)\n");
System.out.format("proof\n");
int a = 0 * 8 + 0 * 4 + 1 * 2 + 1 * 1;
int b = 0 * 8 + 1 * 4 + 0 * 2 + 1 * 1;
System.out.format("a = %s\n", toBinaryString(a).substring(32 - 4, 32));
System.out.format("b = %s\n", toBinaryString(b).substring(32 - 4, 32));
System.out.format("a ^ b = %s\n", toBinaryString(a ^ b).substring(32 - 4, 32));
System.out.format("b ^ a = %s\n", toBinaryString(b ^ a).substring(32 - 4, 32));
System.out.format("\n");
assertEquals(a ^ b, b ^ a);
}
{
System.out.format("(a ^ 0) == a\n");
System.out.format("proof\n");
int a = 0 * 2 + 1 * 1;
System.out.format("a = %s\n", toBinaryString(a).substring(32 - 2, 32));
System.out.format("0 = %s\n", toBinaryString(0).substring(32 - 2, 32));
System.out.format("a ^ 0 = %s\n", toBinaryString(a ^ 0).substring(32 - 2, 32));
System.out.format("\n");
assertEquals(a ^ 0, a);
}
{
System.out.format("(a ^ a) == 0\n");
System.out.format("proof\n");
int a = 0 * 2 + 1 * 1;
System.out.format("a = %s\n", toBinaryString(a).substring(32 - 2, 32));
System.out.format("a ^ a = %s\n", toBinaryString(a ^ a).substring(32 - 2, 32));
System.out.format("\n");
assertEquals(a ^ a, 0);
}
{
System.out.format("((a ^ b) ^ c) == (a ^ (b ^ c))\n");
System.out.format("proof\n");
int a = 0 * 128 + 0 * 64 + 0 * 32 + 0 * 16 + 1 * 8 + 1 * 4 + 1 * 2 + 1 * 1;
int b = 0 * 128 + 0 * 64 + 1 * 32 + 1 * 16 + 0 * 8 + 0 * 4 + 1 * 2 + 1 * 1;
int c = 0 * 128 + 1 * 64 + 0 * 32 + 1 * 16 + 0 * 8 + 1 * 4 + 0 * 2 + 1 * 1;
System.out.format("a = %s\n", toBinaryString(a).substring(32 - 8, 32));
System.out.format("b = %s\n", toBinaryString(b).substring(32 - 8, 32));
System.out.format("c = %s\n", toBinaryString(c).substring(32 - 8, 32));
System.out.format("a ^ b = %s\n", toBinaryString(a ^ b).substring(32 - 8, 32));
System.out.format("(a ^ b) ^ c = %s\n", toBinaryString((a ^ b) ^ c).substring(32 - 8, 32));
System.out.format("b ^ c = %s\n", toBinaryString(b ^ c).substring(32 - 8, 32));
System.out.format("a ^ (b ^ c) = %s\n", toBinaryString(a ^ (b ^ c)).substring(32 - 8, 32));
System.out.format("\n");
assertEquals((a ^ b) ^ c, a ^ (b ^ c));
}
}

private static final String toBinaryString(int a) {
StringBuilder binary = new StringBuilder();
for (int i = 31; i >= 0; i--) {
binary.append(((a >> i) & 1) == 0 ? "0" : "1");
}
return binary.toString();
}
}