signed int and unsigned int

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nguyenthao
    New Member
    • Sep 2007
    • 7

    signed int and unsigned int

    Hi! Can you explain for me? Unsigned int will have range 0 to 232 -1. Signed int will have range - 231 to 231 - 1. Why?
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    I believe unsigned ints have a range of 0 to +4,294,967,295, while signed ints have a range of −2,147,483 ,648 to +2,147,483,647.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by Ganon11
      I believe unsigned ints have a range of 0 to +4,294,967,295, while signed ints have a range of −2,147,483 ,648 to +2,147,483,647.

      Let me explain Ganon11.
      Suppose in which environment there Integer supports X bit long.
      X may be 16 or 32, it does not matter to my explanation.
      For signed int(the Integer signed, may be + or -), the range is -2^(X-1) to +2^(x-1). Because here one bit is reserved for + or -.
      And for unsigned int(the Integer unsigned, it is always +), the range is 0 to (2^X)-1. Here the explanation is Simple.

      Kind regards,
      Dmjpro.

      Comment

      • nguyenthao
        New Member
        • Sep 2007
        • 7

        #4
        Thanks. but why is it (-128)-127, not (-127)-128? Could you please explain more?

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by nguyenthao
          Thanks. but why is it (-128)-127, not (-127)-128? Could you please explain more?
          It may be easier to research the issue yourself than waiting for someone to explain it to you.

          Try starting here.

          Comment

          Working...