Code: Select all
number * 2 ^ leftShiftValue -- same as number << leftShiftValue
math.floor(number / 2 ^ rightShiftValue) -- same as number >> rightShiftValue
Code: Select all
number * 2 ^ leftShiftValue -- same as number << leftShiftValue
math.floor(number / 2 ^ rightShiftValue) -- same as number >> rightShiftValue
*Drools*slime wrote:Lua 5.2 will include a bitwise library AFAIK, and LuaJIT has one as well.
Mike Pall, author of both LuaJIT and BitOp, has publicly criticized the bitwise ops library that will ship with Lua 5.2 because it does not guarantee consistent results across platforms, because bitwise ops has undefined semantics in C.slime wrote:Indeed, although Lua 5.2 will include a bitwise library AFAIK, and LuaJIT has one as well.
As stated, I've found pure Lua implementations to be slow (because they use tables I think). Therefore the advantage to this is that it would a lot faster.schme16 wrote:Whilst it's really interesting to know that it can be done manually like that, I've always used http://lua-users.org/wiki/BitwiseOperators for my projects.
Once again, really neat!
I second that! You do need bitwise operators from time to time.leiradel wrote:I think BitOp would be a great addition to LÖVE. It is cross-platform in that it ensures consistent behavior across all supported platforms which includes Linux, MacOS X and Windows.
And it's free software under the same license as Lua!
No argument there. It's damn slow.BlackBulletIV wrote:I've used that. Its performance is terrible; because it uses tables I believe.
Users browsing this forum: Google [Bot] and 5 guests