DWORD组成与DOWRD标志位

DWORD 定义为 unsigned long 表示 32bit 无符号整数

 

bit = ...1 bit... 位
nybble = 4 bits = 1/2 byte 这个不太清楚
byte = 8 bits = 2 nybbles 1字节=8位   4字节 = 32位 就是2进制32个1或0
WORD = 2 bytes = 4 nybbles = 16 bits
DWORD = 2 WORDs = 4 bytes = 8 nybbles = 32 bits DWORD 2个WORD 4个字节 32位
QWORD = 2 DWORDs = 4 WORDS = ..... = 64 bits

 

Each flag has a different bit set. A DWORD is 32 bits long therefore there are a maximum of 32 different flags that can be used.
每个标志可以在不同的位设置, 一个DWORD类型 表示32位的长度,因此可以有32种不同的标志可以使用。
eg.

Flag1 = ...00000001
Flag2 = ...00000010
Flag3 = ...00000100
Flag4 = ...00001000

and so on

therefore if dwSomething = Flag1 | Flag2 | Flag3
then dwSomething = ...00000001 | ...00000010 | ...00000100
= ...00000111. 

 

 

 

A flag is a value that a function looks at to determine what it should be doing. Arild Fines showed how a function checks to see if a flag is set in the function.
flag(标志位)就是一个函数用来查看并决定什么应该干的值. 
Flags are defined by whoever writes the function, usually they are assigned powers of two because when you OR them together powers of two wont affect each other.
谁写的函数谁定义标志位,通常他们被分配到不同的位上,这样用OR 操作的时候他们不会互相影响
For example, if we defined some flags with decimal values
举例来说,如果你用10进制定义标志值
EX_1 = 1; //00000001 in binary
EX_2 = 2; //00000010 in binary
EX_3 = 4; //00000100 in binary
EX_4 = 8; //00001000 in binary

When we OR them together their values will be superimposed.
当我们采用OR操作时这些值将叠加在一起
EX_1 | EX_2 will be 3, or 00000011 in binary
EX_8 | EX_4 | EX_1 will be 13, or 00001101 in binary

Extracting a specific flag from a dword uses the AND (&) operator. For AND, both bits must be 1 to return 1 or it will return 0.
要检测一个特定标志位是否粗在,可以采用AND操作。如果有就返回非零,么有就返回0


Suppose you have value 00001101 and you want to see if the flag EX_2 is in it, using 00001101 AND EX_2 would return 0 (flag EX_2 is not included) because

00001101
& 00000010
----------
00000000

00001101 AND EX_8 will return EX_8 (the flag is included) because

00001101
& 00001000
----------
00001000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值