PDA

View Full Version : Bit-wise operators in Lua



miked
October 10th, 2004, 12:44 AM
Just an fyi that bit-wise operators are implemented in Girder's implementation of Lua. I.e., if you want 64 and 64 = 64 type logic, you can just use the "and" command. You have to use band(64,64).

Ron originally placed this on the old web site in an intro to Lua, but even then, the actual commands were not listed except in the demo file you could d/l. I couldn't find this info on the new web site, and nothing's on the forums. So this post is just sort of a place holder so that if anyone is searching for bitwise logical operators, you know how to do them!

band(a,b) = logical a and b
bnot(a) = logical not a
bor(a,b) = logical a or b

There are a few more, but I can't remember them at the moment.

Mark F
October 10th, 2004, 03:30 AM
Check out this (http://www.girder.nl/help/girderlua.php) link. :D

miked
October 10th, 2004, 11:30 AM
Yeah, that was the original page I was talking about. But the info in it is not entirely accurate. For instance:



mod, mod(a,b) = b % a.
and, and(a,b) bitwise and operation
or, or(a,b) bitwise or operation
xor xor(a,b) bitwise xor operation
shiftl shiftl(a,b) shift "a" "b" positions to the left.
shiftr shiftr(a,b) shift "a" "b" positions to the right.
bitnot bitnot(a) bitwise not.


The actual command is band(a,b), not and(a,b) . . . .