Re: Writing binary numbers
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Writing binary numbers
- From: Jamie Webb <j@...>
- Date: 2004年1月13日 13:10:03 +0000
On Tuesday 13 January 2004 10:17, Jose Marin wrote:
> Hello.
>
> Is there some way of using the Lua libraries to write
> binary numbers to a file?
Not directly AFAIK, probably because the variations in binary representation
would be confusing. It's not too hard though to decide what representation
you want to use and build the bytes yourself. E.g., to write a positive
32-bit integer in unsigned little-endian format, you could do:
file:write(string.char(math.mod(num, 256), math.mod(num, 65536)/256,
math.mod(num, 16777216)/65536, num/16777216))
-- Jamie Webb