DWORD?

Started by
4 comments, last by JimboC 21 years, 7 months ago
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).
Advertisement
DWORD is the same as an unsigned 32 bit int.

DWORD is a non-standard type.
a DWORD is an unsigned long.
MSVC++ 6DirectX 7
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.
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.
Thanks guys!

This topic is closed to new replies.

Advertisement