How to define the range of integer variable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thiruvenkadam
    New Member
    • Dec 2010
    • 3

    How to define the range of integer variable?

    We know that in 16bit compiler integer variable have 2bytes(16 bits).First MSB for sign and other 15bits for value.By converting this 15bit to value we can get only (-16384 to 16383).Then how can we get the range (-32768 to 32767)??.....pl ease help me to deal with this.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    your math was wrong

    the output you got is equivalent to
    pow(2,14)

    try the mathe
    pow(2,15)

    you will get the answer for sure

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      The range of values that fit into the various types is implementation dependent. The Standard requires each implementation to explicitly specify its integer ranges with the macros of header file limits.h. (Floating point ranges are specified in float.h.)

      The Standard mandates a certain minimum range for each data type, but each implementation is free to make the ranges larger. These minimum ranges are described at the limits.h link.

      "We know that in 16bit compiler integer variable have 2bytes(16 bits).First MSB for sign and other 15bits for value"
      Do not assume any particular encoding scheme. How negative numbers are encoded and whether there is a sign bit are implementation dependent. Your code will be nonportable if you try to make use of special knowledge like that.

      Comment

      Working...