BitAnd: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Fixed version)
(Correct example syntax)
 
Line 23: Line 23:
-- Check if bit 1 is set
-- Check if bit 1 is set
if bitAnd(flags, mask) ~= 0 then
if bitAnd(flags, mask) ~= 0 then
     outputDebugString"Yeah. It's set"
     outputDebugString("Yeah. It's set")
else
else
     outputDebugString"I'm sorry ;("
     outputDebugString("I'm sorry ;(")
end</syntaxhighlight>
end</syntaxhighlight>



Latest revision as of 00:53, 25 November 2024

This function performs a bitwise AND-conjunction on two or more (unsigned) 32-bit integers. See Bitwise operation for more details.

Syntax

uint bitAnd ( uint var1, uint var2, ... )

Required arguments

  • varN: The value you want to perform an AND-conjunction on

Returns

Returns the conjuncted value.

Example

local flags = 0x23 -- binary: 100011b
local mask = 0x20  -- binary: 100000b

-- Check if bit 1 is set
if bitAnd(flags, mask) ~= 0 then
    outputDebugString("Yeah. It's set")
else
    outputDebugString("I'm sorry ;(")
end

To test if a flag is set or not it's easier using bitTest.

See Also