Hello,
I'm trying to insert a single bit into an array of bytes, which would shift all the bits in the byte array to the left.
Say I have a Java byte array as follows:
byte[] byteArray = new byte[2];
byteArray[0] = 0x11
byteArray[1] = 0x00
In binary, this byte array represented as:
0001 0001 0000 0000
Now I want to insert a zero in the third bit position (losing the last bit in the byte array), resulting in:
0000 1000 1000 0000
Is there any easy way to do this in Java? I'm aware of the BigInteger class which can convert the entire byte array to a binary String (then insert that way and convert back), but that seems inefficient.
Thanks in advance.