Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

signed? - what does it mean? 3

Status
Not open for further replies.

fortytwo

Technical User
Apr 18, 2000
206
0
0
GB
Hi all,

I am just learning c++ (have been doing perl for a while) but there is something I am unsure about. What is a signed or unsigned variable and what are they used for?

Thanks. [sig]<p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br> [/sig]
 
In simple terms,

Signed - Negative and Postive integers.
Unsigned - Positive integers only.

Here are the number ranges for C/C++ integer types:

unsigned char: 0 to 255
signed char: -128 to 127
unsigned short: 0 to 65535
signed short: -32768 to 32767
unsigned long: 0 to 4294967296
signed long: -2147483648 to 2147483647

int: same as either short or long depending on machine architecture and compiler. (Usually same as long these days)

Hope this was helpful. [sig][/sig]
 
Thanks Clive. Simple is best :)

Now I understand. [sig]<p>fortytwo<br><a href=mailto:will@hellacool.co.uk>will@hellacool.co.uk</a><br><a href= test site</a><br> [/sig]
 
Also, note that the highest order bit is the sign bit. This is why the range is like it is:

Signed
11111111 = -128

Unsigned it is 255.

Signed
01111111 = 128

Unsigned it is = 128
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top