data conversion question (binary string to 'real string')

Alexander Eisenhuth stacom at stacom-software.de
Fri Jul 25 09:22:38 EDT 2003


Manish Jethani wrote:
> Alexander Eisenhuth wrote:
> 
> 
>>maby I don't see the forest because of all that trees, but :
> 
> 
> Maybe I don't understand your question...
> 
> 
>>from struct import *
>>
>>
>># how can I convert
>>f = float(0.5)
>>
>># with
>>bin_str =  pack('!f', 0.5)
>>
>># now bin_str is '?\x00\x00\x00'
>>
>>
>># to "3F000000" ?????
> 
> 
> ???????????????
> What is your question?
> 
> -Manish
> 
Sorry ...

This two lines converts 0.5 to a string in binary
representation

>>>from struct import *
>>>bin_str =  pack('!f', 0.5)

now bin_str is '?\x00\x00\x00', wich is the representation
of 0.5 in the memory. I need now to convert this binary
string to "3F000000", where '3F' is the hex value of the '?'
in ascii - table.

Any ideas ??

Thaks
Alexander






More information about the Python-list mailing list