Hi,
I was looking for the answer to the same question (with shorts ) and got a hint from foo's answer, but didn't get it to work. So I decided to learn the basics about bits to solve it. I had a lot of help from the
Campfire story "Cat and Mouse Games with Bits" at the site "JavaRanch".
Then I found my own solution of the problem, and then i found that it was almost identical with foo's.

I think that the reason why foo's code didn't work for me was (not only that 8 followed by ) looks like a

) that when you add the bytes bitwise java treats them like integers and fills remaining bytes with ones or zeros depending on sign. In foo's code it can probably be solved by adding the "hexBase" to the second part. Turning this:
Quote:
|
Originally Posted by foo
...
myInt = (myInt << 8 ) | bytes[2];
...
|
to something similar to this:
...
myInt = (myInt << 8 ) | (bytes[2] & hexBase ) ;
...
At least my code is working now.
Thank you all!
Erik