Register forum user name Search FAQ

bit.test

Summary

Bitwise 'test'

Prototype

n = bit.test (a, b, ...)


Description

This takes one or more arguments. All are converted to signed 'long long' (64-bit integers).

The second and subsequent arguments are or'ed together. The result is then and'ed with the first argument. The function returns true if the result of the 'and' is the value being 'and'ed with.

Effectively this tests whether or not various bits are set in the first argument.

The result is a boolean (true or false) and thus can be directly used in "if" tests.

eg.


print (bit.test (0x42, 0x02)) --> true
print (bit.test (0x42, 0x40, 0x02)) --> true
print (bit.test (0x02, 0x03)) --> false (0x01 bit not set)


See also bit.band and bit.bor.

Note that setting a bit can be done with bit.bor.
Clearing a bit can be done with bit.clear.


See Also ...

Lua functions

bit.ashr - Shifts a number right, preserving sign
bit.band - Bitwise 'and'
bit.bor - Bitwise 'or'
bit.clear - Clears one or more bits
bit.mod - Bitwise 'modulus' (remainder after integer divide)
bit.neg - Bitwise 'negate' (ones complement)
bit.shl - Shifts a number left
bit.shr - Shifts a number right
bit.tonumber - Convert a string into a number
bit.tostring - Convert a number into a string
bit.xor - Bitwise 'exclusive or'

Topics

Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua LPEG library
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting
Scripting callbacks - plugins

(Help topic: lua=bit.test)

Documentation contents page


Search ...

Enter a search string to find matching documentation.

Search for:   

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.