All the posts so far are good, but I''m gonna post the strait C way to pack to oversized 32 values (that both are really 16 bits) into a single 32 bit value. This is for those who don''t have the windows macros and such.
// say we have unsigned long origA and unsigned long origB// but both are only using the low 16 bits for their value// and you want to create a 32 value with origA in the High// Order bitsunsigned long packedValue = (origA << 16) + (origB & 0xFFFF);
|
It''s as easy as that. There are 2 important notes. 1) you probably want your packed type to be unsigned. 2) the left shift operator will always bring in Zeros, so origA wont polute origB''s space, but the mask operation is necessary to insure origB doesn''t accidentally step on origA''s space (in case origB has junk in its high bits).
good luck