• Popular Now

• 12
• 12
• 9
• 10
• 13

Archived

This topic is now archived and is closed to further replies.

What IS a DWORD?

This topic is 5876 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Yeah, I''m sure it''s a newb question, but what exactly IS a DWORD? I know it''s some sort of crazy MS typedef, but other than that, I dunno. I looked it up on MSDN but only got it''s general usage, not exactly what it is and what makes it up.

Share on other sites
32 bit unsigned integer

Share on other sites
bit = ...1 bit...
nybble = 4 bits = 1/2 byte
byte = 8 bits = 2 nybbles
WORD = 2 bytes = 4 nybbles = 16 bits
DWORD = 2 WORDs = 4 bytes = 8 nybbles = 32 bits
QWORD = 2 DWORDs = 4 WORDS = ..... = 64 bits
There might be more; if there are, I don't know of them.

EDIT: DWORD stands for Double Word, QWORD for Quad (prefix meaning 4). I suppose the next would be Oct (prefix meaning 8).

"I've learned something today: It doesn't matter if you're white, or if you're black...the only color that REALLY matters is green"
-Peter Griffin

Edited by - matrix2113 on February 17, 2002 7:04:27 PM

Share on other sites
Thankya!
But here''s question 2.
How can DWORDs take statements like:
  DWORD dwBlah;dwBlah = STATEMENT1 | STATEMENT2 | STATEMENT3;

What''s with the pipes and the multiple option thing?
How exactly does the compiler interpret that?

Share on other sites
Its a binary OR operation. Eg - 0 OR 0 = 0, 0 OR 1 = 1, 1 OR 0 = 1 and 1 OR 1 = 1.
In cases like your example its usually used to implement flags. You can then check for whether a flag is set like this:
  if ( dwBlah & aFlag != 0 ) doSomething();

Share on other sites
Ok, now, what are the flags?
They obviously have to hold some value (0 or 1?).
How exactly is that assigned?

Share on other sites
Each flag has a different bit set. A DWORD is 8 bits long therefore there are a maximum of 8 different flags that can be used.

eg.

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

and so on

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

Share on other sites
Sorry, my brain wasn''t working today - A DWORD is 32 bits long therefore there is a maximum of 32 possible flags.

Share on other sites
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.

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.

For example, if we defined some flags with decimal values

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.

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.

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

by the way, I''ve been using single bytes to explain the use of flags and AND and OR so that you could see the individual 0''s and 1''s without me having to type out 32 of them out to represent a double word. I''m sure you already figured that though