Create a 32-bit integer from 2 16-bit integer

  • Thread starter Thread starter Tony Liu
  • Start date Start date
Tony Liu said:
Thanks, in addition, how to create a 64-bit integer from 2 32-bit integers?

Apply the same advice again - the only difference is that you have to
cast the int to long before shifting:

long combined = (((long)highBits)<<32) | lowBits;
 
Thanks again, but how to get back the 2 32-bit integers from the 64-bit
integer?

Thanks in advance
Tony
 
Tony Liu said:
Thanks again, but how to get back the 2 32-bit integers from the 64-bit
integer?

Just use & to mask bits and shift right appropriately. If this isn't
enough, please consult a book about bit shifting - I'm not going to
give you an answer for every single possible thing you might want to do
with bit shifting.
 
Back
Top