[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: PATCH: hex numbers and bit ops**
**From**: Mike Pall <mikelu-0509@...>
**Date**: Mon, 5 Sep 2005 17:27:17 +0200

Hi,
Philippe Lhoste wrote:
> Why not a variable number of arguments?
> y = math.bitor(0x12, 0x34, 0x56)
> looks nicer than
> y = math.bitor(0x12, math.bitor(0x34, 0x56))
> Isn't it?
Well, that would be easy. I'll change it if I have
to release another bugfix version.
> > y... = math.bitfield(x, start [, len] ...)
> > 'start' is the bit position relative to the lsb (bit 0)
> > It's a right/left shift for a positive/negative 'start'.
> > It's a pure shift if 'len' is omitted.
> > Otherwise the result is masked to 'len' valid bits.
>
> Not very user friendly, it is quite hard to figure what the examples do...
Sure, docs could be improved. The following sentence may help:
math.bitfield(x, start, len) extracts a bitfield from the
number 'x' starting at bit number 'start' with length 'len'.
IMHO the examples show exactly what it's doing ...
> Why not make specific functions for shifting bits?
Umm? The two-argument bitfield(x, y) _is_ a plain shift.
It's (y >= 0) ? (x >> y) : (x << -y) in C notation.
Make an alias local bitshift = math.bitfield if you want. :-)
Bye,
Mike