0

Is there any way to access the actual bits that are stored in memory for the floating-point variables in Python?

I'm imagining something similar to bin() function (but with floats as inputs).

I came across various Python solutions to convert a floating-point number into its IEEE-754 representation (see below), but they all require several steps of computation, and I imagine one should have the ability to just read these values directly from memory - without the unnecessary manipulations. Or am I wrong? Then why is that impossible?

Here are the examples of what I've found:

Python doesn’t provide any inbuilt method to easily convert floating point decimal numbers to binary number.

Vladimir Fokow
  • 3,728
  • 2
  • 5
  • 27
  • Everything in Python is an object. `float` objects in particular in CPython are just thin wrappers around C doubles – juanpa.arrivillaga May 31 '21 at 01:30
  • Probably https://stackoverflow.com/questions/16444726/binary-representation-of-float-in-python-bits-not-hex solves my problem. Thanks. I couldn't understand their solution at first. Should research more about `struct`. – Vladimir Fokow May 31 '21 at 01:36

0 Answers0