Need help with an array problem.

James Stroud jstroud at mbi.ucla.edu
Mon Oct 2 18:02:02 EDT 2006


SpreadTooThin wrote:
> Basically I think the problem is in converting from a 32 bit integer to
> a 16 bit integer.
> 
> I have two arrays:
> import array
> 
> a = array.array('L', [65537])
> b = array.array('H', [0])
> 
> b[0] = a[0]
> 
> Which gives an overflow message....
> So can't I truncate the long by discaring the upper bits ..
> Like  b[0] = 0x0000FFFF & a[0]
> 
> How does one normally cast an object from long to short?

Take the modulo 65536?

py> array.array('H', (array.array('L', [65537%65536])))
array('H', [1])


James


-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list