• ### Announcements

#### Archived

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

# What IS a DWORD?

## 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

##### Share on other sites
DWORD is a typedef from the Windows API. Most such typedefs are anachronisms. For example, a WORD is 16 bits and a DWORD is 32 bits (as has been said), but those names are currently misnomers. You see, a "word" refers the the addressing size of the target processor. When the Windows API was first devised, a word was 16 bits, hence the 16-bit size for the WORD type. But most processors these days address 32 bits at a time, so they have 32-bit words. For backwards compatibility, WORD stayed the same, even though—from the name—it should be 32-bits. Other types like LPARAM and WPARAM have become the same size (32 bits), even though WPARAM used to be 16-bits as is indicated by the W prefix (which stands for WORD). So, it''s confusing, especially since Intel parlence has followed the same trend of backwards compatibility with naming. But don''t forget what a real word is—that it''s dependent on the processor.

##### Share on other sites
Thankyou everyone, I get it now
Sorry about the multitude of questions though.
I just like to understand something inside out and it drives me nuts when I don''t.

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627648
• Total Posts
2978393

• 10
• 12
• 22
• 13
• 33