Archived

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

DWORD?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could someone please explain to me what a DWORD is and how you could find an average of a number of them? I can add, subtract, multiply and divide, cast them as other types, but I can''t seem to add two DWORDs and divide the total in half - everything I''ve tried results in 0 or an error. Visual Studio.NET''s help files don''t seem to have any definition (they list int, float, etc., but not DWORD).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
DWORD is the same as an unsigned 32 bit int.

DWORD is a non-standard type.

Share this post


Link to post
Share on other sites
DWORD is typically Windows-specific. Its something Microsoft defines in their headers. As other have mentioned, its just an unsigned int (or unsigned long, which are the same thing under Win32, both 32 bits).

There is no problem with adding two together and dividing the total in half. However, it may be that you want to do a float divide and stick the answer in a float.

float answer = dwordTotal / 2.0f;

instead of

DWORD answer = dwordTotal / 2;

Otherwise you might wind up casting a fractional value to an integer (implicitly) and you''ll lose information, maybe even resulting in 0 when the answer should have been 0.5, for example.

Share this post


Link to post
Share on other sites
DWORD is a double WORD

a WORD is 16 bits of memory
DWORD is 32 bits.

it is guaranteed to be 32bits no matter what processor you use. In future this will make a difference when the standard int changes size.

Share this post


Link to post
Share on other sites