[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: io.format (was: Reported to the Bloat Police: string.pack, .unpack and .packsize!)
- From: Peter Melnichenko <mpeterval@...>
- Date: Sat, 22 Aug 2015 09:54:16 +0300
On Fri, Aug 21, 2015 at 11:58 PM, Sean Conner <sean@conman.org> wrote:
> <snip>
> But here's both to compare and contrast:
>
> val = x:sub(1,1):byte() * 2^24
> + x:sub(2,2):byte() * 2^16
> + x:sub(3,3):byte() * 2^8
> + x:sub(4,4):byte()
>
> val = x:sub(1,1):byte() << 24
> | x:sub(2,2):byte() << 16
> | x:sub(3,3):byte() << 8
> | x:sub(4,4):byte()
>
By the way, `x:sub(i, i):byte()` can be written as `x:byte(i)`, so it's
less verbose than that.
-- Peter