I am trying to insert one bit into a byte array that will shift all 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 form, this array of bytes is represented as:
0001 0001 0000 0000
Now I want to insert zero in the third bit position (lose the last bit in the byte array), resulting in:
0000 1000 1000 0000
Is there an easy way to do this in Java? I know the BigInteger class, which can convert the entire byte array to a binary string (then paste this path and convert back), but it seems inefficient.
Thanks in advance.
mike boldischar
source share