If I understand your question correctly, you are looking for the reverse operation with what you had in the question.
Here's how you can do it (ugly code with ghosts, etc., but shows what happens to bits):
byte source = 0xA3; // source = 10100011 = 163 // get bits from source byte lowbits = (byte)((int)source & 7); // lowbits = 00000011 = 3 byte highbits = (byte)((int)source >> 3); // highbits = 00010100 = 20
Note that at this moment lowbits contains a value that is between 0 and 7 (not 0 and 5), and highbits contains a value that is between 0 and 31 (not 0 and 250).
// use bits to create copy of original source byte destination = (byte)(((int)highbits << 3) | (int)lowbits); // destination = 10100011
Also note that if highbits contains a value greater than 31, then some bits will be deleted by this operation. And if lowbits contains a value greater than 7, this can lead to overwriting some bits from highbits .
source share