I am trying to combining two integers to a long in Java. Here is the code I am using:
Long combinedValue = (long) a << 32 | b;
When a = 0x03
and b = 0x1B56 ED23
, I am able to get the expected value (combinedValue = 13343583523
in long).
However, when my a = 0x00
and b = 0xA2BF E1C7
, I get a negative value, -1567628857
, instead of 2730484167
. Can anyone explain why shifting an integer 0 by 32 bits causes the first 32 bits become 0xFFFF FFFF
?
Thanks