Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bit Question from a Newbie 2

Status
Not open for further replies.

japhy

Programmer
Sep 27, 2004
12
US
Probably a very easy question...thanks for your patience in answering it.

I'm trying to combine two 16 bit words into 1 32 bit DWORD...the two 16 bit words are contained in unsigned ints.

which operator can combine these in this way?

Thanks very much
 
If you want them side by side, you need to use the left shift operator on one of them. Ex.
Code:
unsigned short one = 0x1234;
unsigned short two = 0x5678;
unsigned int combined = (one << 16) | two;
// Now combined is 0x12345678.
 
Option 2:

WORD one=0x1234;
WORD two=0x5678;

DWORD three;
HIWORD(three)=one;
LOWORD(three)=two;

result -> 0x12345678
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top