Sean
Sean

Reputation: 879

Lua true Binary I/O

I read this question, and I checked it myself.

I use the following snippet:

f = io.open("file.file", "wb")
f:write(1.34)
f:close()

This creates the file, into which 1.34 is written. This is same as : 00110001 00101110 00110011 00110100 , that is binary codes for the digit 1, the decinal point, then 3 and finally 4.

However, I would like to have printed 00111111 10101100 11001100 11001101, which is a true float representation. How do I do so?

Upvotes: 2

Views: 447

Answers (1)

Paul Kulchenko
Paul Kulchenko

Reputation: 26744

You may need to convert it to binary representation, using something similar to this answer. This discussion on serialization of lua numbers may also be useful.

Upvotes: 2

Related Questions