Bit Packing in java
807606Apr 13 2007 — edited Apr 14 2007Hi,
Im using Java to do bit packing for an assignment.
Ive got the compression working, but im having problems with decompression.
The example im having problems with is: Ive packed an integer into 8 bits and it crosses a byte boundary. I.e. [1 _0110000][1_0010110].
The _ show the start and end of the character 01100001 (97)
When I get the first byte I shift left by 1 to get 96, I then OR this result with the next byte shifted 7 to the right.
The next byte is -106 (-ve because of the 1 in the high position, this is the bit I need to get from 96 -> 97.
When I shift -106 seven bits to the right I get -1, instead of 1, why is this?