I am trying to transfer a certain number of bits in a byte to the beginning of an int but its not working out as planned.
public int transfer(byte b, int offset, int len, int dest, int bitsInUSe){
byte mask = (byte) ((byte) ((1 << len) - 1) << offset);
dest = dest<< bitsInUSe;
dest = b & mask;
return dest ;
}
eg, with offset 2 and len 3 of byte 00111000 should produce the int> 00000000000000000000000000000110
I only need to put the bits at the beginning of the int but I would need to move any bits that have previously been assigned to the left so they are not overridden, hence the bitsInUse variable.