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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.