The following method should swap the high nibble in a byte with the low nibble in a byte.
The following code dosn't work if the lower nibble is above 0111
if it is it returns a negative number...
Does anyone know what im doing wrong ?
public static void main(String[] args){
byte inByte = (byte)0x09;
byte out;
int by1 = (inByte >> 0) & 0x0f;
int by2 = (inByte >> 4) & 0x0f;
System.out.println(by1);
System.out.println(by2);
out = (byte)((by1 << 4 | by2 << 0) & 0xff);
System.out.println(out);
}
Thanks for your help,
Paul