short s1 = ...
short s2 = ...
short result = (short) (s1 ^ s2);
This is the most efficient way to XOR two short
s together. It does not run into the overhead of creating BigInteger
s and the cast will never cause an overflow issue as both s1
and s2
are short
s to begin with.