range of int() type.

K

KraftDiner

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...
 
S

Simon Forman

KraftDiner said:
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.
 
G

Gabriel Genellina

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!
http://www.yahoo.com.ar/respuestas
 
T

Terry Reedy

KraftDiner said:
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
 
K

KraftDiner

Terry said:
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 ?
 
F

Felipe Almeida Lessa

23 Aug 2006 17:28:48 -0700 said:
This is obvious... but how do I crop off the high order bits if
necessary?
a[0]&0xFFFF ?

min(a[0], 0xFFFF) ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top