Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Bit Packing in java

807606Apr 13 2007 — edited Apr 14 2007
Hi,

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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 12 2007
Added on Apr 13 2007
4 comments
754 views