NAME

bit - bitwise operations (bitlib)


OVERVIEW

bitlib is a C library for Lua 5.x that provides bitwise operations.


INSTALLATION

The provided Makefile builds a shared library called bit.so, which can be installed on LUA_CPATH and used with require.


REFERENCE

Lua functions provided:

bit.bnot

  bit.bnot(a)

returns the one's complement of a

bit.band

  bit.band(w1,...)

returns the bitwise and of the w's

bit.bor

  bit.bor(w1,...)

returns the bitwise or of the w's

bit.bxor

  bit.bxor(w1,...)

returns the bitwise exclusive or of the w's

bit.lshift

  bit.lshift(a,b)

returns a shifted left b places

bit.rshift

  bit.rshift(a,b)

returns a shifted logically right b places

bit.arshift

  bit.arshift(a,b)

returns a shifted arithmetically right b places

bit.mod

  bit.mod(a,b)

returns the integer remainder of a divided by b

Additional Notes

All function arguments should be integers. The number of bits available for logical operations depends on the data type used to represent Lua numbers; this is typically 8-byte IEEE floats, which give 53 bits (the size of the mantissa).

The logical operations start with ``b'' for ``bit'' to avoid clashing with reserved words; although ``xor'' isn't a reserved word, it seemed better to use ``bxor'' for consistency.


VERSION

This is bitlib release 20.


CREDITS

by Reuben Thomas <rrt@sc3d.org> http://luaforge.net/projects/bitlib

Thanks to John Passaniti for his bitwise operations library, some of whose ideas I used, and to Thatcher Ulrich for portability fixes.


CONTACT

Please report bugs and make suggestions to the email address above, or use the LuaForge trackers.


LICENSE

It is copyright Reuben Thomas 2000-2006, and is released under the MIT license, like Lua (see http://www.lua.org/copyright.html; it's basically the same as the BSD license). There is no warranty.