-1

I am looking for basically the exact same thing as this question but in Python.

How can I obtain the bytes in memory of a single-precision floating point variable in Python? For instance if I have a variable x = 0.65 I need to get some form of the list [97, 102, 38, 63].

0

2 Answers 2

0

Bytes:

x = 0.65
print(list(struct.pack("!f", x)))
Sign up to request clarification or add additional context in comments.

Comments

0

Try:

import struct

ba = bytearray(struct.pack("f", 0.65))
print(ba[0], ba[1], ba[2], ba[3])

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.