Re: Python equivalent to the "A" or "a" output conversions in C

2012-06-19 Thread Aldrich DeMata
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/~

Re: Python equivalent to the "A" or "a" output conversions in C

2012-06-19 Thread jmfauth
On Jun 19, 9:54 pm, "Edward C. Jones" wrote: > On 06/19/2012 12:41 PM, Hemanth H.M wrote: > > > >>> float.hex(x) > > '0x1.5p+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.flo

Re: Python equivalent to the "A" or "a" output conversions in C

2012-06-19 Thread Edward C. Jones
On 06/19/2012 12:41 PM, Hemanth H.M wrote: >>> float.hex(x) '0x1.5p+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?

Re: Python equivalent to the "A" or "a" output conversions in C

2012-06-19 Thread Mark Lawrence
On 19/06/2012 17:23, Edward C. Jones wrote: Consider the following line in C: printf('%a\n', x); where x is a float or double. This outputs a hexadecimal representation of x. Can I do this in Python? See this http://docs.python.org/library/string.html#format-examples -- Cheers. Mark Lawrence

Re: Python equivalent to the "A" or "a" output conversions in C

2012-06-19 Thread Alexander Blinne
On 19.06.2012 18:23, Edward C. Jones wrote: > Consider the following line in C: >printf('%a\n', x); > where x is a float or double. This outputs a hexadecimal representation > of x. Can I do this in Python? Don't know why there is no format character %a or %A in python, but the conversion is

Re: Python equivalent to the "A" or "a" output conversions in C

2012-06-19 Thread Hemanth H.M
Are you looking for : >>> x=10 >>> hex(x) '0xa' >>> x=10.5 >>> float.hex(x) '0x1.5p+3' On Tue, Jun 19, 2012 at 9:53 PM, Edward C. Jones wrote: > hexadecimal -- *'I am what I am because of who we all are'* h3manth.com *-- Hemanth HM * -- http://mail.pyth

Python equivalent to the "A" or "a" output conversions in C

2012-06-19 Thread Edward C. Jones
Consider the following line in C: printf('%a\n', x); where x is a float or double. This outputs a hexadecimal representation of x. Can I do this in Python? -- http://mail.python.org/mailman/listinfo/python-list