Python equivalent to the "A" or "a" output conversions in C
Aldrich DeMata
aldrich.demata at gmail.com
Wed Jun 20 02:55:16 EDT 2012
Use the binascii module:
>>> import numpy as np
>>> x = np.float32(3.14)
>>> x.dtype
dtype('float32')
>>> binascii.hexlify(x)
'c3f54840'
The final result is little endian so it should be read as 0x4048f5c3
instead.
You can verify the conversion using the link below:
http://gregstoll.dyndns.org/~gregstoll/floattohex/
aldrich
On Tue, Jun 19, 2012 at 2:54 PM, Edward C. Jones <edcjones at comcast.net>wrote:
> On 06/19/2012 12:41 PM, Hemanth H.M wrote:
>
> >>> float.hex(x)
>> '0x1.5000000000000p+3'
>>
>> Some days I don't ask the brightest questions. Suppose x was a numpy
> floating scalar (types numpy.float16, numpy.float32, numpy.float64, or
> numpy.float128). Is there an easy way to write x in
> binary or hex?
>
>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120620/318a26b7/attachment.html>
More information about the Python-list
mailing list