How can I get the binary format of a float type tensor?

The problem I met is that how can I get a binary format like 101101010010(assume it’s IEEE754 format, although it’s not) from its corresponding float type value like 0.365(this does not correspond with the binary format before)

1 Like

You could transform the tensor to a numpy array and use np.binary_repr on it.

1 Like

np.binary_repr only works with integers and not floats. numpy.binary_repr — NumPy v1.22 Manual

Just following up if any new ideas came forward to get the binary/hex format out of a torch float tensor.

I’ve found one by on Github but it seems like manually converting the data to get the binary. Just wondering if there is any better way. For example, if I can directly read the binary from the memory address or something.

Any response would be much appreciated. Thanks in advance!

2 Likes