lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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