[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (alpha-rc3) now available
- From: David Manura <dm.lua@...>
- Date: Tue, 23 Nov 2010 20:36:56 -0500
On Tue, Nov 23, 2010 at 7:44 PM, Miles Bader <miles@gnu.org> wrote:
> Patrick Rapin <toupie300@gmail.com> writes:
>> I call them get and set. We used them quite a lot to deal with bit
>> fields from hardware registers. This is how they could be defined:
>>
>> bit32.get(x, disp [, nbbits]) : returns the bit slice taken from
>> number 'x', starting at bit # 'disp', and of size 'nbbits' bits (1 by
>> default).
>>
>> bit32.set(val, x, disp [, nbbits]) : inserts the value 'val' as a bit
>> slice into number 'x', starting at bit position 'disp', and of size
>> 'nbbits' bits (1 by default). The number 'val' must be an integer
>> between 0 and 2^nbbits-1.
>
> I think the "traditional" names for these operations (e.g., instruction
> names on CPUs that have such operations) are "extract" and "insert".
>
> [And I think those names are more clear than "get" and "set"]
Considering a bit pattern as a sequence of bits, then this function is
closest to string.sub. The analogue of string.reverse could be
implied too. [1]
Luckily, we don't do string operations that way:
string.sand(string.shift("abcdef", -2), "\xff\xff\xff") == "cde").
[1] http://lua-users.org/lists/lua-l/2010-10/msg00291.html