lua-users home
lua-l archive

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


On Wed, Oct 23, 2019 at 11:44 PM Russell Haley <russ.haley@gmail.com> wrote:
>
> Hi,
>
> Can anybody help me convert this 5.2 code to 5.3? I suck at binary stuff.
>
> My attempts to replicate bit32.extract yielded little worth posting:

It may help to look at the source code for bit32.extract:
https://www.lua.org/source/5.2/lbitlib.c.html#b_extract

The function is quite short, and the actual work with bitwise
operations is a one-liner (if you consider the "mask" macro to be part
of that one-liner). It essentially right-shifts it by an amount equal
to the desired low bit, then ANDs it with a mask equal in width to the
desired field size (which in your case is just 1).