Caché MultiValue Basic Reference BITAND
 Search:

Returns the bitwise AND for two bit strings.
Synopsis
`BITAND(bitstring1,bitstring2)`
Arguments
 bitstring A bit string, specified as an expression that resolves to a positive integer. For example, the integer 64 specifies the bitstring 1000000. The maximum bitstring value is 9223372036854775807.
Description
The BITAND function compares two bit strings bit-by-bit, and returns a bitstring that is the logical AND bitwise comparison of the two strings. Both bitstring values are specified as positive integers. The returned value is also expressed as a positive integer.
The following is the truth table for BITAND:
 bitstring1 = 0 bitstring1 = 1 bitstring2 = 0 0 0 bitstring2 = 1 0 1
A bitstring can be expressed as either a number or as a string. A number is converted to canonical form, with leading plus signs and leading and trailing zeros omitted. If either argument evaluates to the null string or a non-numeric string it is assumed to have a value of 0. A string is parsed as a number until a non-numeric character is encountered. Thus “7dwarves” is parsed as 7.
Examples
The following example specifies a bitstring1 of 14 (binary 1110), and a bitstring2 of 9 (binary 1001). Bitwise AND comparison results in the binary string 1000, the integer value of which is 8:
`PRINT BITAND(14,9);  ! Returns 8`
The following example specifies a bitstring1 of 14 (binary 1110), and a bitstring2 of 6 (binary 110). Bitwise AND comparison results in the binary string 0110, the integer value of which is 6:
`PRINT BITAND(14,6);  ! Returns 6`
The following example specifies a bitstring1 of 65 (binary 1000001), and a bitstring2 of 62 (binary 111110). Bitwise AND comparison results in the binary string 0000000, the integer value of which is 0:
`PRINT BITAND(65,62);  ! Returns 0`
The following example specifies two bitstrings with the same integer value. Bitwise AND comparison of a number with itself always results in the number:
`PRINT BITAND(64,64);  ! Returns 64`