Unsigned vs. Signed?

This is a discussion on Unsigned vs. Signed? within the C++ Programming forums, part of the General Programming Boards category; Hi, is an unsigned integral type negative , and a signed integral type positive ? Or is it the exact ...

  1. #1
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Unsigned vs. Signed?

    Hi,

    is an unsigned integral type negative, and a signed integral type positive? Or is it the exact opposite? There was some confusion on which is which in the book I'm reading.
    Last edited by Programmer_P; 12-22-2009 at 12:10 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,430
    unsigned implies that the possible values are non-negative; signed implies that the possible values can be negative.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    Note that the MSB of the signed value is used to define if the value is negative or positive, also the value stored for signed types is cut in half to those values stored in an unsigned storage type. Food for thought.

  4. #4
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Ok, thanks. One more question:

    Are all basic types, such as int, char, etc. signed by default?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,430
    Quote Originally Posted by Programmer_P
    Are all basic types, such as int, char, etc. signed by default?
    No. short int, int and long int are indeed signed integer types, but whether char is signed or unsigned is implementation defined. Consequently, if you want a signed char, use a signed char.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 08-11-2008, 11:02 PM
  2. Heap corruption using zlib inflate
    By The Wazaa in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2007, 12:43 PM
  3. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  4. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21