Dealing with odd numbers of bits

Joined
Jan 16, 2011
Messages
1
Reaction score
0
Hello all

First post here so hopefully I'm not asking for information that is already here.

I'm working on a project and I need to read in two bytes and then get some information out of them.

From the two bytes I need to find two numbers; offset and length.

The first 13 bits are the offset and the 3 (lsb) are the length.

I'm not entirely sure of the best way of finding out the offset from the 13 bits. I'm not sure if I need to store them into an int or a short as it's an odd number of bits.

I'm assuming that I need to mask off the 3 lsb and then turn the first 13 bits into an int but I'm not sure if that is correct.

From the information I've got relating to the offset; it is stored as a negative integer in 2's complement.

I need to do this in Java and any assistance anyone can provide would be greatly appreciated.

Thanks

Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top