How to convert a float to its binary or hex representation in Python?
Hi, I'm trying to use Python to determine the machine representation of an array of floats. This is the code I have so far, which does the job, but it's very hacky and not very efficient. I was thinking something could be done with bitwise masking. Any thoughts on making this more direct and efficient are greatly appreciated. A 'hexdump binary' indicates that the conversion is indeed correct.
Code:
#!/usr/bin/python |
I'm far from being a Python expert, but if I understand what you want correctly, struct.pack may be what you are looking for. You can use that to get a binary format of various types.
|
All times are GMT -5. The time now is 10:12 AM. |