Scripting > UNICOM Intelligence Function Library > Miscellaneous functions > BitAnd
 
BitAnd
Performs a bitwise AND on two or more numeric values and returns the result.
Syntax
BitAnd(Val1 [, Vals, ...])
Parameters
Val1
Type: Long
First data value.
Vals
Type: None
Variable number of other values.
(return)
Type: Long
All values AND-ed together.
Remarks
Vals is a list if variants, which are converted to Long before they are used. If one or more of them cannot be converted to a Long value, an error occurs.
The return value is a number with only the bits set that are set in Val1 and in all the other value arguments. If the current data value is NULL, Val1 is 0 and the return value is 0. If no other arguments are supplied, the return value is Val1.
This function is similar to using And as a bitwise operator in Visual Basic.
Example
BitAnd is useful for testing whether certain bits have been set. For example, some properties store a numeric value in which the bits are used to record true or false values that represent whether various flags have been set. A type definition is typically used to define the various flags. For example, the Element.Flag property in the MDM is used to record whether a category is one or more of various special category types, such as Other Specify, Don't know, or Exclusive (which means that the category is single-choice when it is used in a multiple response question). The values are defined in the CategoryFlagConstants type definition and because the Flag is used as a bit field, it can store more than one “value”.
The following mrScriptBasic code snippet loops through a variable's categories and uses the BitAnd function to test each one to see whether it is defined as exclusive:
Dim myCategory

For each myCategory in Field.ElementInstances
  If BitAnd(myCategory.Flag, CategoryFlagConstants.flExclusive)   Then
    ' This is an exclusive category...
  End If
Next
For an example of using BitAnd in combination with other bit functions, see BitOr and BitNot. For an example of using BitAnd when cleaning data in a DataManagementScript (DMS) file, see Example 4: Cleaning other question types.
See also
BitNot
Miscellaneous functions