如何把两个byte类型转换成一个word类型?
如何把两个byte类型转换成一个word类型,其中一个byte为高八位,一个为低八位,请高手指教!谢谢
[解决办法]
连续存放的话,直接转换
独立的话,可以memcpy
[解决办法]
byte h, l;
WORD w;
w = h < <8 | l;
[解决办法]
word = (WORD)byte1 < <1+ byte2
[解决办法]
http://msdn2.microsoft.com/en-us/library/ms632663.aspx
MAKEWORD Macro
[解决办法]
WORD MAKEWORD(BYTE bLow,BYTE bHigh);
[解决办法]
要不直接使用windows提供的宏 MAKEWORD,要不就参考它的实现方法,
以下引自MSDN
MAKEWORD
The MAKEWORD macro creates an unsigned 16-bit integer by concatenating two given unsigned character values.
WORD MAKEWORD(
BYTE bLow, // low-order byte of short value
BYTE bHigh // high-order byte of short value
);
Parameters
bLow
Specifies the low-order byte of the new short value.
bHigh
Specifies the high-order byte of the new short value.
Return Values
The return value is an unsigned 16-bit integer value.
Remarks
The MAKEWORD macro is defined as follows:
#define MAKEWORD(a, b) \
((WORD) (((BYTE) (a)) | ((WORD) ((BYTE) (b))) < < 8))