Caché MultiValue Basic Reference
BITNOT


Sets the specified bit in a bitstring to its opposite value.
Synopsis
The
BITNOT function defines a bit string using
bitstring and changes (flips) one bit of that bit string at the location specified by
bitno. Both values are specified as positive integers. If the bit specified by
bitno has a value of 0,
BITNOT sets it to 1. If the bit specified by
bitno has a value of 1,
BITNOT sets it to 0.
Both
bitstring and
bitno can be expressed as either numbers or as strings. These 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.
The
BITNOT function always changes the specified bit. The
BITSET function only sets the specified bit if its value is 0. The
BITRESET function only sets the specified bit if its value is 1.
The following example specifies a
bitstring of 64 (binary 1000000), and
bitno sets bit position 0 to its opposite. This results in the binary string 1000001, the integer value of which is 65:
PRINT BITNOT(64,0); ! Returns 65
The following example specifies a
bitstring of 64 (binary 1000000), and
bitno sets bit position 4 to its opposite. This results in the binary string 1010000, the integer value of which is 80:
PRINT BITNOT(64,4); ! Returns 80
The following example specifies a
bitstring of 65 (binary 1000001), and
bitno specifies setting bit position 0 to its opposite. This results in the binary string 1000000, the integer value of which is 64:
PRINT BITNOT(65,0); ! Returns 64
The following example specifies a
bitstring of 8 (binary 1000), and
bitno specifies setting bit position 4 to its opposite. The
bitstring has an implicit bit position of 4 with a value of 0. Setting this bit to 1 returns the binary string 11000, the integer value of which is 24:
PRINT BITNOT(8,4); ! Returns 24
The following example specifies a
bitstring of 1 (binary 1), and
bitno sets bit position 0 to its opposite. This results in the binary string 0, the integer value of which is 0:
PRINT BITNOT(1,0); ! Returns 0