BYTE,WORD,DWORD的大小及一些特殊的"高低位宏"

 

一、定义

VC6.0Microsoft Visual Studio/VC98/Include/windef.h 里,定义了BYTE,WORD,DWORD

typedef unsigned long       DWORD;

typedef unsigned char       BYTE;

typedef unsigned short      WORD;

在Visual C++ 6.0中,char型长度为1字节,short型长度为2字节,int和long型长度都为4字节,因此可以认为BYTE与WORD,DWORD定义的变量分别获得了1字节,2字节,4字节内存,正与BYTE与WORD,DWORD的字面意义相符。

:

BYTE=unsigned char(完全等同):       8

WORD=unsigned short(完全等同):  16

DWORD=unsigned long(完全等同): 32

 

 

 

下面是一些平时用得比较少的宏:

二、Window 

1.LOBYTE( 从给定16位值中提取低位字节)

BYTE LOBYTE(

  WORD wValue  // value from which low-order byte is retrieved

);

#define LOBYTE(w)   ((BYTE) (w))

如:WORD w=-0x1234;//w在内存中以补码形式存储:0xedcc,0xcc(低地址) 0xed(高地址)

printf("w的低位字节:%x/n",LOBYTE(w));// 出:w的低位字节:cc

 

2.HIBYTE( 从给定16位值中提取高位字节)

BYTE HIBYTE(

  WORD wValue  // value from which high-order byte is retrieved

);

#define HIBYTE(w)   ((BYTE) (((WORD) (w) >> 8) & 0xFF))

如:printf("w的高位字节:%x/n",HIBYTE(w));// 输出:w的高位字节:ed

 

3.LOWORD(从给定32位值中提取低位word)

WORD LOWORD(

  DWORD dwValue  // value from which low-order word is retrieved

);

#define LOWORD(l)   ((WORD) (l))

: DWORD l = 0x12345678;//l在内存中存储为:0x78,0x56,0x34,0x12

printf("l的低位字:%x/n",LOWORD(l));// 输出:l的低位字:5678

 

4.HIWORD(从给定32位值中提取高位word)

WORD HIWORD(

  DWORD dwValue  // value from which high-order word is retrieved

);

#define HIWORD(l)   ((WORD) (((DWORD) (l) >> 16) & 0xFFFF))

:printf("l的高位字:%x/n",HIWORD(l));//输出:l的高位字:1234

5.MAKEWORD(将两个给定的无符号字符值连接成为一个16位整数)

WORD MAKEWORD(

  BYTE bLow,  // low-order byte of short value

  BYTE bHigh  // high-order byte of short value

);

#define MAKEWORD(a, b) /

((WORD) (((BYTE) (a)) | ((WORD) ((BYTE) (b))) << 8))

: BYTE bLow=0x34,bHigh=0x12;

printf("MAKEWORD(%x,%x)=%x/n",bLow,bHigh,MAKEWORD(bLow,bHigh));

输出结果为: MAKEWORD(34,12)=1234

 

6.MAKELONG(将两个给定的16位值连接成为一个32位整数)

DWORD MAKELONG(

  WORD wLow,  // low-order word of long value

  WORD wHigh  // high-order word of long value

);

#define MAKELONG(a, b) /

    ((LONG) (((WORD) (a)) | ((DWORD) ((WORD) (b))) << 16))

 

如:WORD vLow=0x5678,vHigh=0x1234;

printf("MAKELONG(%x,%x)=%x/n",vLow,vHigh,MAKELONG(vLow,vHigh));

输出结果:MAKELONG(5678,1234)=12345678

 

from:http://blog.csdn.net/zhangyang0402/archive/2008/12/13/3509850.aspx

 

转载于:https://www.cnblogs.com/dartagnan/archive/2010/10/14/2126893.html

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
<p> <strong><span style="font-size:20px;color:#FF0000;">本课程主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的Java学习者</span></strong> </p> <p> <span style="color:#FF0000;"><strong><span style="font-size:18px;">1. 包含:<span style="color:#FFFF00;background-color:#FF0000;">项目源码、</span><span style="color:#FFFF00;background-color:#FF0000;">项目文档、数据库脚本、软件工具</span>等所有资料</span></strong></span> </p> <p> <span style="color:#FF0000;"><strong><span style="font-size:18px;">2. 手把手的带你从零开始部署运行本套系统</span></strong></span> </p> <p> <span style="color:#FF0000;"><strong><span style="font-size:18px;">3. 该项目附带的源码资料可作为毕设使用</span></strong></span> </p> <p> <span style="color:#FF0000;"><strong><span style="font-size:18px;">4. 提供技术答疑和远程协助指导</span></strong></span><strong><span style="font-size:18px;"></span></strong> </p> <p> <br /> </p> <p> <span style="font-size:18px;"><strong>项目运行截图:</strong></span> </p> <p> <strong><span style="font-size:18px;">1)系统登陆界面</span></strong> </p> <p> <strong><span style="font-size:18px;"><img src="https://img-bss.csdn.net/202002241015433522.png" alt="" /><br /> </span></strong> </p> <p> <strong><span style="font-size:18px;"><strong><span style="font-size:18px;">2)学生模块</span></strong></span></strong> </p> <p> <strong><span style="font-size:18px;"><img src="https://img-bss.csdn.net/202002241015575966.png" alt="" /></span></strong> </p> <p> <strong><span style="font-size:18px;"><strong><span style="font-size:18px;">3)教师模块</span></strong></span></strong> </p> <p> <strong><span style="font-size:18px;"><img src="https://img-bss.csdn.net/202002241016127898.png" alt="" /></span></strong> </p> <p> <strong><span style="font-size:18px;"><strong><span style="font-size:18px;">4)系统管理员</span></strong></span></strong> </p> <p> <strong><span style="font-size:18px;"><img src="https://img-bss.csdn.net/202002241016281177.png" alt="" /></span></strong> </p> <p> <strong><span style="font-size:18px;"><img src="https://img-bss.csdn.net/202002241016369884.png" alt="" /></span></strong> </p> <p> <strong><span style="font-size:18px;"><br /> </span></strong> </p> <p> <strong><span style="font-size:18px;"><strong><span style="font-size:18px;">更多Java毕设项目请关注我的毕设系列课程 <a href="https://edu.csdn.net/lecturer/2104">https://edu.csdn.net/lecturer/2104</a></span></strong></span></strong> </p> <p> <strong><span style="font-size:18px;"><br /> </span></strong> </p>
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页