0

I have a 32bit floating point decimal in sting format. I want to get it into float format.

For exmaple, how do I convert this string: '01000010000000001110111010011000' into this float: 32.233001709

Perhaps there is some intermediate step where the string is converted into binary: 0b01000010000000001110111010011000?

  • Does this answer your question? [How to convert a binary (string) into a float value?](https://stackoverflow.com/questions/8751653/how-to-convert-a-binary-string-into-a-float-value) – picobit Oct 20 '22 at 18:59
  • You may find your answer here: https://stackoverflow.com/questions/8751653/how-to-convert-a-binary-string-into-a-float-value – Omar Oct 20 '22 at 19:01

1 Answers1

0

Adapting my answer from one of the questions posted as a possible duplicate:

s2 = '01000010000000001110111010011000'
struct.unpack('f', struct.pack('I', int(s2, 2)))[0]

It's a three-step process. First convert the binary string to int. Second convert that to a sequence of bytes. Third convert those bytes to float.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622