When I XOR a byte lets say -1(in byte) with 2(int) I get -3 as a result whereas I want the operation to give me a positive int. This is due to the 2's complement representation and type promotion. I want to know if there a way I can use unsigned byte in java.
int x = 2;
byte y = -1;
System.out.println(x^y);
Output
-3
I found two excellent similar questions here and here. But I want some method or bitwise operation to return an int which can be later converted into byte without 2's complement representation.