Max M <[EMAIL PROTECTED]> wrote in news:41bf121e$0$280
[EMAIL PROTECTED]:
>
> ##
> st = '80 00 00 00'
>
> import binascii
> import struct
>
> s = ''.join([binascii.a2b_hex(s) for s in st.split()])
> v = struct.unpack("f", s)[0]
> print v
> ##
This one worked great for what I was trying to do.
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> One example I tried was:
>
> wibble = struct.unpack("f", struct.pack("l", long(conv_str, 16)))
> OverflowError: long int too large to convert to int
You can't fit 0x8000L into a signed 32-bit integer, use 'L' for
an unsigned one.
Christos TZOTZIOY Georgiou wrote:
s = "".join(x).decode("hex")
I am not sure I remember in which version of Python the hex codec was
added, but it is handy.
Of course, binascii could do this since 2.0 or so, but not
having to import another module *is* nice:
>>> 'ff12'.decode('hex')
'\xff\x12'
>>>
On Tue, 14 Dec 2004 16:57:02 +0100, rumours say that "Fredrik Lundh"
<[EMAIL PROTECTED]> might have written:
>how about:
>
># convert to byte string
>import struct
>s = "".join([chr(int(c, 16)) for c in x])
>v = struct.unpack("!f", s)
I think that the third line in the snippet abo
># convert to byte string, via the array module
>import array, struct
>a = array.array("B", [int(c, 16) for c in x])
>v = struct.unpack("!f", )
eh? should be:
# convert to byte string, via the array module
import array, struct
a = array.array("B", [int(c, 16) for c in
Max M wrote:
> Oh, programmers loves this kind stuff. You should get tons of answers.
data = '80 00 00 00'
import Image
v = Image.fromstring("F", (1, 1), data, "hex", "F;32BF").getpixel((0, 0))
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Each of these numbers is a Hex byte making up a four byte (32 bit
Big-Endian) IEEE float. I have read this data into Python using
readlines and then line.split(). This gives me:
['80', '00', '00', '00']
Oh, programmers loves this kind stuff. You should get tons of answers.
<[EMAIL PROTECTED]> wrote:
> Newbie Python programmer here, so please be patient. I have spent all
> day googling for an answer to my problem, but everything I try fails to
> work (or works from the Interpreter with a set value but not from my
> code with dynamic values).
>
> Okay, here is the gen