range of int() type.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KraftDiner

    range of int() type.

    What is the range of a variable of type int()

    eg:
    i = int()
    print i.max() # 0xFFFFFFFF
    print i.min() # 0x00000000

    is it a signed 16 bit or 32 bit or is it unsigned 16 or 32...
    I've noticed that it can be incremented into a new class of type
    long...

  • Simon Forman

    #2
    Re: range of int() type.

    KraftDiner wrote:
    What is the range of a variable of type int()
    >
    eg:
    i = int()
    print i.max() # 0xFFFFFFFF
    print i.min() # 0x00000000
    >
    is it a signed 16 bit or 32 bit or is it unsigned 16 or 32...
    I've noticed that it can be incremented into a new class of type
    long...
    |>import sys
    |>sys.maxint
    2147483647
    >From the sys module docs:
    maxint
    The largest positive integer supported by Python's regular integer
    type. This is at least 2**31-1. The largest negative integer is
    -maxint-1 -- the asymmetry results from the use of 2's complement
    binary arithmetic.

    Peace,
    ~Simon

    P.S. ints and longs are becoming unified soon.

    Comment

    • KraftDiner

      #3
      Re: range of int() type.


      Simon Forman wrote:
      KraftDiner wrote:
      What is the range of a variable of type int()

      eg:
      i = int()
      print i.max() # 0xFFFFFFFF
      print i.min() # 0x00000000

      is it a signed 16 bit or 32 bit or is it unsigned 16 or 32...
      I've noticed that it can be incremented into a new class of type
      long...
      >
      |>import sys
      |>sys.maxint
      2147483647
      >
      So what type / class should one use to represent a 16 bit integers
      (signed or unsigned)?



      From the sys module docs:
      maxint
      The largest positive integer supported by Python's regular integer
      type. This is at least 2**31-1. The largest negative integer is
      -maxint-1 -- the asymmetry results from the use of 2's complement
      binary arithmetic.
      >
      Peace,
      ~Simon
      >
      P.S. ints and longs are becoming unified soon.

      Comment

      • Gabriel Genellina

        #4
        Re: range of int() type.

        At Wednesday 23/8/2006 18:53, KraftDiner wrote:
        |>import sys
        |>sys.maxint
        2147483647
        >
        >So what type / class should one use to represent a 16 bit integers
        >(signed or unsigned)?
        Plain int.
        If you need the overflow at 32K/64K, try: x & 0xFFFF



        Gabriel Genellina
        Softlab SRL





        _______________ _______________ _______________ _____
        Preguntá. Respondé. Descubrí.
        Todo lo que querías saber, y lo que ni imaginabas,
        está en Yahoo! Respuestas (Beta).
        ¡Probalo ya!


        Comment

        • Terry Reedy

          #5
          Re: range of int() type.


          "KraftDiner " <bobrien18@yaho o.comwrote in message
          news:1156370039 .116224.154430@ 75g2000cwc.goog legroups.com...
          >
          So what type / class should one use to represent a 16 bit integers
          (signed or unsigned)?
          For most purposes, Python just has integers, with 'small' ones (depending
          on the machine) handled more efficiently. For special purposes, you may
          want to use the array or struct modules.

          tjr



          Comment

          • KraftDiner

            #6
            Re: range of int() type.


            Terry Reedy wrote:
            "KraftDiner " <bobrien18@yaho o.comwrote in message
            news:1156370039 .116224.154430@ 75g2000cwc.goog legroups.com...

            So what type / class should one use to represent a 16 bit integers
            (signed or unsigned)?
            >
            For most purposes, Python just has integers, with 'small' ones (depending
            on the machine) handled more efficiently. For special purposes, you may
            want to use the array or struct modules.
            >
            tjr
            Ok so the bottom line is..
            if I have two arrays...

            a = array.array('L' )
            a.append(65536L )
            b = array.array('H' )
            b.append(a[0])

            I will get the error:
            File "<stdin>", line 1, in ?
            OverflowError: unsigned short is greater than maximum

            This is obvious... but how do I crop off the high order bits if
            necessary?
            a[0]&0xFFFF ?

            Comment

            • Felipe Almeida Lessa

              #7
              Re: range of int() type.

              23 Aug 2006 17:28:48 -0700, KraftDiner <bobrien18@yaho o.com>:
              This is obvious... but how do I crop off the high order bits if
              necessary?
              a[0]&0xFFFF ?
              min(a[0], 0xFFFF) ?

              --
              Felipe.

              Comment

              Working...