I need to convert a 32 bit floating point number to 4 bytes for an embedded system using the Squirrel language. I was hoping I could just bit shift and mask the bytes into separate parts, doing something like:
bytes = [
(myfloat >> 24) & 0xff,
(myfloat >> 16) & 0xff,
(myfloat >> 8) & 0xff,
(myfloat ) & 0xff,
]
However, this gives me a type error saying that you can't bit shift on a float.
The only other thing I see in the docs is the tointeger
function, so I could cast to an integer and then get the nondecimal part, but even then I will also need to go the other way from bytes to a float later.
Any ideas?