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.

2
  • Everything in Python is an object. float objects in particular in CPython are just thin wrappers around C doubles Commented May 31, 2021 at 1:30
  • Probably stackoverflow.com/questions/16444726/… solves my problem. Thanks. I couldn't understand their solution at first. Should research more about struct. Commented May 31, 2021 at 1:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.