On 2008-03-05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Is there a simple way to twiddle the bits of a float? In particular, I
> would like to round my float to the n most significant bits.
>
> For example - 0.123 in binary is 0.000111111
> Rounding to 4 bits I get 0.0001.
>
> I can pack and unpack a float into a long
> e.g.
> struct.unpack('I',struct.pack('f',0.123))[0]
> but then I'm not sure how to work with the resulting long.
>
> Any suggestions?
Just use the bitwise and/or/not operators: & | ~
--
Grant Edwards grante Yow! Half a mind is a
at terrible thing to waste!
visi.com
--
http://mail.python.org/mailman/listinfo/python-list