What went wrong here is that something like this
((byte)sT << 56)
does not do what you want. What it actually does, is cast sT
to a byte
(which it already is), then it's implicitly converted to an int
(because you do math with it), and then it's shifted left by 24 (shift counts are masked to limit them to less than the size of the left operand).
So actually instead of casting to a narrow type, you should cast to a wide type, like this:
((long)sT << 56)
Also, note that implicitly converting an int
to long
sign-extends it, which means that if nId
is negative, you would end up complementing all the other fields (xor with all ones is complement).
So try this:
((long)sT << 56) | ((long)srcT << 48) | ((long)aId << 32) | (nId & 0xffffffffL)
I've also changed the xor's to or's, it's more idiomatic for combining non-overlapping things.