Advertisement

unsigned

Started by February 13, 2000 12:52 PM
12 comments, last by Pseudo_Code 24 years, 7 months ago
I have looked in all of the books, and what does an unsigned variable do? What difference does it make whether it is signed or unsigned? and yes, I am very new to C++. I am trying to learn as much about the language before I learn directx.
Mostly it''s good for giving you more numbers... for instance, if you only want positive numbers and negatives don''t mean anything in your context, you lose half the possible numbers you would have if you use a signed variable, but with unsigned, you get zero to however high you can go with that number of bits.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Advertisement
Thanks alot! But, I have another question, what are WORDs and DWORDs? I really appreciate your, and anybody''s help! This helps me out a lot more than you would think. thank you for reading my questions.
WORDS are 16 bits of data. DWORDS are 32 bits of data. I think the MS headers define them both to be unsigned integer types (short and long respectively).
That''s really not C/C++ more like win/dx typedefs
something like
typedef unsigned _int16 WORD;
typedef unsigned _int_32 DWORD;
basically, a WORD is a unsigned 16 bit integer, and a DWORD a 32 bit unsigned integer
Well, int and unsigned (and lots of other types) are actually part of C++. WORD, DWORD, and other types like that (generally all caps) are part of Microsoft''s Visual C++ VERSION of C++. They are usually just different names for some other type. As an example, VisualC++6 defines WORD to be "A 16-bit unsigned integer" while DWORD is "A 32-bit unsigned integer". The D stands for ''double'' indicating that DWORD is twice as long as WORD. And WORD is a common term in computer science/engineering for the ''standard'' size of one "chunk" of memory. However, this would imply that VC6 thinks most memory is used in 16-bit chunks, which IS NOT TRUE. (Grumble, stupid Microsoft making it impossible to explain things.)

Anyways, the easiest way to find out what these things are is to look in the Visul C++ help files. Just search for whatever term you want (WORD, DWORD, etc...) and it should point you towards a list of the MS data types. Hope this helps!

-Brian
Advertisement
A byte is 8 bits.
A word is 16 bits.
A dword (double word) is 32 bits.

This is not a Microsoft thing.

This is true on any platform and any chipset (even if it isn't defined by C) and is a basic comp-sci thing. If it wasn't a 32 bit system would have 32 bit sized bytes and instead of 64 Mb your system would have 16 Mb.

On 32-bit Windows, for example a long int and an int are the same size. This wasn't true on 16 bit windows (which is why WPARAM and LPARAM are the same length even though the names say they shouldn't be) and probably won't be true on the 64-bit systems. The ANSI C standard explicity states that variable sizes are system dependent. ( And just because I'm sick of these ANTI-NEWBIE rants: This is something you could clearly find in the ANSI standard)


Using WORD or DWORD ensures that any platform or any chipset knows the exact size of a variable.

Edited by - logistix on 2/13/00 1:37:03 PM
-the logistical one-http://members.bellatlantic.net/~olsongt
Thanks for your help! I really appreciate it. You''ve helped me alot!
quote: Original post by logistix
A byte is 8 bits.
A word is 16 bits.
A dword (double word) is 32 bits.

This is not a Microsoft thing.

This is true on any platform and any chipset (even if it isn''t defined by C) and is a basic comp-sci thing. If it wasn''t a 32 bit system would have 32 bit sized bytes and instead of 64 Mb your system would have 16 Mb.

Actually it''s not true on any platform. Old PDP''s used 6-bit bytes. It''s one of the reasons that the older network protocols don''t define things in terms of bytes, but in terms of octets. And technically a word on a modern MIPS-2000 machine is 32 bits.

On Intel x86 processors a byte is 8bits, a word is 16bits and a dword is 32bits.

Computer science defines byte as the addressing width, and word as the processor''s register width. Obviously this got mangled on the x86 family when moving from the 286 to 386. It''s only because of legacy register widths (i.e. the AX registers vs. the EAX registers) that the 386 processors and on are considered to have 16 bit words.
With an unsigned integer, it can hold numbers from 0 to 65535. Once you go passed 65535, it ''wraps around'' to zero.

with a signed integer, it goes from -32767 to 32767.

Both unsigned, and signed integers are 2 bytes in size.
3D Math- The type of mathematics that'll put hair on your chest!

This topic is closed to new replies.

Advertisement