range of int() type.

KraftDiner bobrien18 at yahoo.com
Wed Aug 23 20:28:48 EDT 2006


Terry Reedy wrote:
> "KraftDiner" <bobrien18 at yahoo.com> wrote in message
> news:1156370039.116224.154430 at 75g2000cwc.googlegroups.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 ?




More information about the Python-list mailing list