<< Click to Display Table of Contents >> Navigation: Multi-Protocol MasterOPC Server > Lua 5.1 Reference Manual > Function library > The BIT Library > Bitwise Data Operations |
Sets on/off the specified bit of a number, and returns the modified number.
Function arguments are:
1 – number
2 – bit value (true or false)
3 – bit number (starting with 0)
Example
local d=1
d=bit.BitToData(d,true,1); --d=3
server.Message("d=",d);
Returns a value of the specified bit of a number.
Function arguments are:
1 – number
2 – bit number (starting with 0)
Example
local bit=false;
local d=1
bit=bit.BitFromData(d,0); --bit=true
server.Message("bit=",bit);
Performs the operation "bitwise NOT"; returns a bitwise-inverted value of the argument.
Example
--a = 01101101
b=bit.BitNot(a);
--b=10010010
Returns a result of the operation "bitwise AND" with arguments. Number of arguments may be greater than 2.
Example
--a = 01101101
--b = 11001001
c=bit.BitAnd(a,b);
--c = 01001001
Returns a result of the operation "bitwise OR" with arguments. Number of arguments may be greater than 2.
Example
--a = 00101101
--b = 10001001
c=bit.BitOr(a,b);
--c = 10101101
Returns a result of the operation "bitwise XOR" with arguments. Number of arguments may be greater than 2.
Example
--a = 00101101
--b = 10001001
c=bit.BitXor(a,b);
--c = 10100100
Returns a result of the operation "shift to the left by specified number of bits" (cut bits are not transferred).
Arguments:
1 – number to be shifted
2 – shift as number of bits
Example
--a = 00101101
b=bit.BitLshift (a,3);
--b = 01101000
Returns a result of the operation "shift to the right by specified number of bits" (cut bits are not transferred).
Arguments:
1 – number to be shifted
2 – shift as number of bits
Example
--a = 00101101
b=bit.BitRshift(a,3);
--b = 00000101
Returns a result of the operation "arithmetic shift to the right by specified number of bits".
Arguments:
1 – number to be shifted
2 – shift as number of bits
Example
--a = 11111010
b=bit.BitArshift(a,1);
--b = 11111101