BitAnd
Performs a bitwise AND on two or more numeric values and returns the result.
Syntax
BitAnd(<value> [, <value>, ...])
Parameters
<value>
Type: Long
Data value. Separate multiple values by using commas.
(return)
Type: Long
All values AND-ed together.
Notes
Values 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 the values. If the current data value is NULL, <value> is 0 and the return value is 0. If no other arguments are supplied, the return value is <value>.
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