# two uint16 types to uint32

This is a discussion on two uint16 types to uint32 within the C Programming forums, part of the General Programming Boards category; Hi, Got a problem to solve. How to do it? Must use most significant and least significant. Lets say uint16 ...

1. ## two uint16 types to uint32

Hi,

Got a problem to solve. How to do it? Must use most significant and least significant. Lets say uint16 u16X = 10; and uint16 u16Y = 8; Now I must convert it into a uint32, which holds both of these values. Bit logic ... I have to put one number ahead of other. Can't figure it out. I hope you guys understand.

2. You could use a union to do this and let the compiler figure it out, or you could manually write the code to put the two uint16's into a uint32 (one in the upper 16 bits, the other in the lower 16 bits).

3. Something like
uint32 r = ((uint32)u16X << 16) | u16Y;

4. Or, you could do it with numeric operations rather than by bit fiddling. Just make use of the fact that numeric operations on unsigned types work with modulo arithmetic.