Signed and unsigned

This is a discussion on Signed and unsigned within the C++ Programming forums, part of the General Programming Boards category; What exactly are signed and unsigned numbers? Please clarify. Thanks.....

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91

    Smile Signed and unsigned

    What exactly are signed and unsigned numbers? Please clarify.
    Thanks..

  2. #2
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    In a strictly lingual sense, signed numbers may be negative or positive, while unsigned numbers are taken as positive. Usually, unsigned numbers can represent greater values, since in most implementations no space is left for a sign in an unsigned number.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Like the monkey explained, signed numbers can be positive or negative. Unsigned numbers are always positive.

    In C++, unsigned variables can hold larger numbers, since all 8 bits (assuming the variable is 1 byte) can be used. While in signed variables, the last bit is used for the sign.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Strictly speaking, unsigned numbers are nonnegative, not necessarily positive.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91

    Smile

    How about the range? Why 0 to 255 for unsigned and -128 to 127 for signed in 1 byte? I don't quite get that. Can somebody please explain further?

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Signed types need 1 bit for the sign, which means the maximum absolute value is approximately 1/2 that of an unsigned type. The C and C++ standards allow three types of signed integral arithmetic: two's complement, ones' complement, and sign-magnitude. Most modern machines use two's complement, in which there is one extra value at the negative end (for example -128 to +127). Ones' complement and sign-magnitude have a symmetric range (for example -127 to +127).

    Edit: http://en.wikipedia.org/wiki/Signed_...epresentations
    Last edited by robatino; 09-18-2007 at 12:29 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 06-04-2009, 02:03 PM
  2. How to tell a type is signed or unsigned?
    By meili100 in forum C++ Programming
    Replies: 22
    Last Post: 05-08-2008, 08:21 PM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 08:22 AM
  5. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 06:35 AM

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