lua-users home
lua-l archive

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


Mike Pall wrote:
Well, that would be easy. I'll change it if I have
to release another bugfix version.

I've implemented bit arithmetic as a seperate library. Just thought I'd list the functions I have, in bad pseudocode, in case it leads to inspiration:

set(value, bit): return value | (1 << bit)
clear(value, bit): return value & ~(1 << bit)
switch(value, bitsOn, bitsOff): return value | bitsOn & ~bitsOff
not(value): return ~value
and(value, ...): return value & ...
or(value, ...): return value | ...
xor(value, ...): return value ^ ...
implies(value, ...): return value implies ...
nand(value, ...) return value nand ...
nor(value, ...) return value nor ...
xnor(value, ...) return value xnor ...
shiftLeft(value, shift) return value << shift
shiftRight(value, shift) return value >> shift

I've got the separate functions for each because I felt it better to trade off a little space for the speed advantage of not having to compose boolean operators from primitives.

--
Lisa
http://www.thecommune.org.uk/~lisa/