
Caché MultiValue Basic Reference
BITTEST



Server:docs2 
Instance:LATEST 
User:UnknownUser 


Tests the value of the specified bit in a bitstring.
Synopsis
The
BITTEST function defines a bit string using
bitstring and tests the value of one bit of that bit string at the location specified by
bitno. If the bit specified by
bitno has a value of 0,
BITTEST returns 0. If the bit specified by
bitno has a value of 1,
BITTEST returns 1.
Both
bitstring and
bitno are specified as positive integers. These arguments can be expressed as either numbers or as strings. Numbers are converted to canonical form, with leading plus signs and leading and trailing zeros omitted. If either argument evaluates to the null string or a nonnumeric string it is assumed to have a value of 0. A string is parsed as a number until a nonnumeric character is encountered. Thus “7dwarves” is parsed as 7.
You can use the
BITSET function to set individual bits.
The following examples specify a
bitstring of 14 (binary 1110), and use
bitno to specify each bit in turn, returning the value of the bit:
x = BITSET(14,3); ! Returns 14
PRINT BITTEST(x,0); ! Returns 0
PRINT BITTEST(x,1); ! Returns 1
PRINT BITTEST(x,2); ! Returns 1
PRINT BITTEST(x,3); ! Returns 1
The following example specifies a
bitstring of 8 (binary 1000), and
bitno specifies bit position 4. The
bitstring has an implicit bit position of 4 with a value of 0.
PRINT BITTEST(8,4); ! Returns 0