Garry's Mod Wiki

bit.band

  number bit.band( number value, number otherValues = nil )

Description

Performs the bitwise and for all values specified.

Arguments

1 number value
The value to be manipulated.
2 number otherValues = nil
Values bit to perform bitwise "and" with. Optional.

Returns

1 number
Result of bitwise "and" operation.

Example

local a = 170 -- 10101010 in binary form local b = 146 -- 10010010 in binary form print( bit.band( a, b ) )
Output: 130 (10000010 in binary form)

Example

Tests for a specific damage type.

local myDamage = bit.bor( DMG_BULLET, DMG_RADIATION ) local isBulletDamage = bit.band( myDamage, DMG_BULLET ) == DMG_BULLET print( isBulletDamage )