> 1. If i wanted to just read a particular number of
> bytes, for example, byte 4-8 in a 15 byte data
> stream, how would i do that in python please?
Once you've read your 15 bytes into a string, you can use slices to extract the sub-string that you desire.
a = 'abcdefghijklmnp'
b = a[4:9]
will extract the bytes with subscripts 4 through 8 inclusive.
> 2. Does anybody know how to convert a 32 bit hex data
> into IEEE 754 floating point in python please!
IEEE 754 has more than one 32 bit representation for data. However, I'll assume you mean something like a single precision float. If that's the case check out.
to make sure. Probably the simplest way is to use the struct module to unpack it as a float. If you have your 32 bits as a binary string in variable h, you would just do:
and it would return the data as a float object.
However,you mention that it is "hex" data. So if it's a formatted string represented in hex, you'll need to get the data into a packed binary representation first. One way would be to use the built in int function int(h, 16) for example, and then unpack that.