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

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

Post by Tony Li » Thu, 21 Aug 2003 00:29:00


Hi, how to create a 32-bit integer from 2 16-bit integer?
Thanks
Tony
 
 
 

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

Post by Jon Skee » Thu, 21 Aug 2003 00:33:22


Shift and or them:

int combined = (highBits << 16) | lowBits;

--
Jon Skeet - < XXXX@XXXXX.COM >
http://www.yqcomputer.com/ ~skeet/
If replying to the group, please do not mail me too

 
 
 

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

Post by Tony Li » Thu, 21 Aug 2003 00:54:35

Thanks, in addition, how to create a 64-bit integer from 2 32-bit integers?

Tony
 
 
 

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

Post by Jon Skee » Thu, 21 Aug 2003 00:59:14


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;

--
Jon Skeet - < XXXX@XXXXX.COM >
http://www.yqcomputer.com/ ~skeet/
If replying to the group, please do not mail me too
 
 
 

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

Post by Duncan McN » Thu, 21 Aug 2003 01:03:40

1 loo roll
2. sticky tape
3. glue



Duncan McNutt
Microsoft Product Deactivation Team
 
 
 

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

Post by Tony Li » Thu, 21 Aug 2003 01:13:18

Thanks again, but how to get back the 2 32-bit integers from the 64-bit
integer?

Thanks in advance
Tony




integers?
 
 
 

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

Post by Jon Skee » Thu, 21 Aug 2003 01:21:22


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.

--
Jon Skeet - < XXXX@XXXXX.COM >
http://www.yqcomputer.com/ ~skeet/
If replying to the group, please do not mail me too