I have a feeling that this is a pretty trivial question, but I'm at a dead end. In my application, I am manipulating the lookup table with an int pair. I thought it would be easier to combine the two ints into one long and use one long as a key instead. Based on background C, I was hoping this would work:
int a, b; long l = (long)a << 32 | b;
My attempts to repeat this in Java upset me. In particular, since there are no unsigned integral types, I cannot avoid automatically expanding the sign of b (a has a left shift, so it doesn't matter). I tried using b & 0x00000000FFFFFFFF , but this unexpectedly has no effect. I also tried the rather ugly (long)b << 32 >> 32 , but it seemed to be optimized by the compiler.
I was hoping to do it strictly using bit manipulation with primitives, but I'm starting to wonder if I need to use some kind of buffer object for this.
java
Oscar Korz
source share