在对一个进程的通信部分做分析时反复遇到了这四类函数,特做此记录。
LOWORD:取32位数的低16位
HIWORD:取32位数的高16位
LOBYTE:取16位数的低8位
HIBYTE:去16位数的高8位
ps:LOBYTE、HIBYTE应用于32位数时,会取32位数后16位数的高低8位。
官方说明
LOWORD macro
Retrieves the low-order word from the specified value.
Syntax
C++
WORD LOWORD( DWORD dwValue );
Parameters
dwValue
The value to be converted.
Return value
Type: WORD
The return value is the low-order word of the specified value.
LOBYTE macro
Retrieves the low-order byte from the specified value.
Syntax
C++
BYTE LOBYTE( WORD wValue );
Parameters
wValue
The value to be converted.
Return value
Type: BYTE
The return value is the low-order byte of the specified value.
随便编段代码来验证:
#include "stdafx.h"
#include<stdio.h>
#include<Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
int a = 258; // 0000 0001 0000 0010
int b = 65539; // 0000 0000 0000 0001 0000 0000 0000 0011
printf("lobyte_a:%d\n",LOBYTE(a));
printf("hibyte_a:%d\n",HIBYTE(a));
printf("loword_b:%d\n",LOWORD(b));
printf("hiword_b:%d\n",HIWORD(b));
return 0;
}
输出结果: