Supressing sign-extension when upcasting or shifting in Java
<p>I have a feeling this is a rather trivial question, but I'm stumped. In my application I'm keying things in a lookup table with a pair of ints. I thought it would be easier to concatenate the two ints into one long and use the single long as a key instead. Coming from a C background, I was hoping something like this would work:</p>

<pre><code>int a, b;
long l = (long)a &lt;&lt; 32 | b;
</code></pre>

<p>My attempts to replicate this in Java have frustrated me. In particular, because there are no unsigned integral types, I can't seem to avoid the automatic sign-extension of b (a gets left-shifted so its irrelevant). I've tried using <code>b &amp; 0x00000000FFFFFFFF</code> but it surprisingly has no  effect. I also tried the rather ugly <code>(long)b &lt;&lt; 32 &gt;&gt; 32</code>, but it seemed to be optimized out by the compiler.</p>

<p>I was hoping to do this strictly using bit manipulation with primitives, but I'm starting to wonder if I need to use some sort of buffer object to achieve this.</p>
