Tests the value of the specified bit in a bitstring.
||The 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.
||The bit position in bitstring to return the value of. An expression that resolves to a positive integer. Bit positions are counted right to left, beginning with position 0. The maximum bitno value is 62. A fractional bitno is truncated to its integer portion. A negative bitno generates a <FUNCTION> error.
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
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 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.
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
© 1997-2019 InterSystems Corporation, Cambridge, MA