<div><div>Use the binascii module:</div><div><br></div><div>>>> import numpy as np</div><div>>>> x = np.float32(3.14)</div><div>>>> x.dtype</div><div>dtype('float32')</div><div>>>> binascii.hexlify(x)</div>
<div>'c3f54840'</div><div><br></div></div><div>The final result is little endian so it should be read as 0x4048f5c3 instead.</div><div><br></div><div>You can verify the conversion using the link below:</div>
<div><a href="http://gregstoll.dyndns.org/~gregstoll/floattohex/" target="_blank">http://gregstoll.dyndns.org/~gregstoll/floattohex/</a></div>
<div><br></div><div>aldrich</div><br><div class="gmail_quote">On Tue, Jun 19, 2012 at 2:54 PM, Edward C. Jones <span dir="ltr"><<a href="mailto:edcjones@comcast.net" target="_blank">edcjones@comcast.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 06/19/2012 12:41 PM, Hemanth H.M wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>>> float.hex(x)<br>
'0x1.5000000000000p+3'<br>
<br>
</blockquote>
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<br>
binary or hex?<span><font color="#888888"><br>
<br>
<br>
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br>