Linked Questions
26 questions linked to/from Binary representation of float in Python (bits not hex)
17
votes
3
answers
18k
views
Get the "bits" of a float in Python? [duplicate]
I am looking for the Python equivalent of Java's Float.floatToBits.
I found this Python: obtain & manipulate (as integers) bit patterns of floats but does anyone know of a less complicated way?
13
votes
4
answers
12k
views
Obtain & manipulate bit pattern of float as integer [duplicate]
In Python 2.5, I have a float and I'd like to obtain and manipulate its bit pattern as an integer.
For example, suppose I have
x = 173.3125
In IEEE 754 format, x's bit pattern in hexadecimal is ...
1
vote
0
answers
1k
views
Float number to 32 bits IEEE754 single precision is 64 bits [duplicate]
When using this code
import bitstring
f = 1.0e+00
b = bitstring.pack('>d', f)
b.bin
I get 64 bits
001111111111000000000000000000000000000000000000000000000000000
But I need to get Float (IEEE754 ...
0
votes
0
answers
66
views
How to see the binary value of float that's really stored in memory. Python [duplicate]
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 ...
1
vote
0
answers
57
views
Python print floating point number in binary? [duplicate]
Is there a way to print a floating point number in binary in Python? Something like
>>> f"{0.5:b}"
0.1
? The above doesn't work.
158
votes
24
answers
551k
views
Convert hex to binary
I have ABC123EFFF.
I want to have 001010101111000001001000111110111111111111 (i.e. binary repr. with, say, 42 digits and leading zeroes).
How?
0
votes
2
answers
14k
views
Float to Binary and Binary to Float in Python
Can anyone tell me how to convert a float number to 32-bit binary string and from a 32-bit binary string to a float number in python?
'bin' function in python works only for integers.
I need a ...
3
votes
1
answer
5k
views
Extracting floating-point significand and exponent in NumPy
I would like to be able to extract the significand and exponent of floating-point numbers in NumPy. Getting the exponent as an integer is fine and ok for the significand. Getting the significand as a ...
14
votes
1
answer
5k
views
Numpy's loadtxt and Pandas read_csv result in different float64 representation
The following code is part of a bigger project.
In my project I have to read a large text file, with probably many million lines, with each line having a pair of decimals separated by space.
An ...
1
vote
3
answers
2k
views
Multiplying a huge number times random() (Python)
Problem: Generate large binary strings (length 2000+). Do it quickly, as this generateRandom() function will be called 300,000 times in the algorithm.
Attempted Solutions: Generate 3 or 4 binary ...
2
votes
2
answers
2k
views
Tensorflow bit-wise NOT operation for floats
I have a Tensorflow boolean vector that I need to bit-wise invert such that all the values that are 0 (False) becomes 1 (True) and vice-versa. tf.logical_not exists, but it only takes Boolean vectors. ...
0
votes
3
answers
2k
views
Recognising an input() as either a str, float, or int and acting accordingly
Python beginner here. I'm writing a program that uses an infinite loop and allows the user to enter key terms to access different 'tools' or 'modules'.
Within one of these 'modules', the user can ...
6
votes
2
answers
497
views
Is there a python equivalent of the octave command `format bit`?
In octave, all the numerical output subsequent to the command format bit will show the native bit representation of numbers as stored in the memory. For example,
octave:1> format bit
octave:2> ...
-2
votes
1
answer
2k
views
How to converting floating point number
A converting between the decimal to single-precision floating,but i intro to this,so did any useful references or any summarize can help?
Thousand Thanks!
so,the python function will be like
require ...
0
votes
1
answer
2k
views
Python: convert a float to 4 uint8
I have some software which takes as input the following format (which is doing it for MATLAB):
[typecast(single(doubleNumber),'uint8') 0]
where doubleNumber is an arbitrary floating number. How can I ...