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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DWord problems

Status
Not open for further replies.

zaphy2k2

Programmer
Dec 23, 2001
30
GB
Hi,

I have to DWORDs from a digital board, both 8bit. One is the 'Lo' part, the other is the 'Hi' part. How do i merge them into a single DWORD of 16bit length? VB or C++ would be grand.

cheers

zaphy
 
:Blink, blink:

Er, by definition a DWORD on a 32bit processor is 32 bits. I'll assume that you mean you have to BYTEs that you want to combine into a WORD. That's pretty easy.

In C++:
unsigned char Hi;
unsigned char Low;
unsigned short Combined;

Combined = (Hi << 8) | Low;

<< is the shift up operator. It will shift a number up by the number of bits you specify (in this case, 8). This is like multiplying Hi by 2 to the 8th power.

| is the bitwise OR operator. It will allow you to combine numbers bitwise, and it is slightly faster than +. But you only want to use it when numbers do not overlap. For example, you wouldn't want to use Hi | Low in place of Hi + Low, because they wouldn't give you the same results.

---Evil Peer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top