PilotScript Bitset Functions

The following bitset functions are available for PilotScript components.

Bitset functions treat the data in the underlying property as a bitset, that is, as a sequence of on/off bits. For example, the set of all atoms in any substructure returned by substructure search, is a bitset. (Y To ttest whether a given property is stored as a bitset, use the GetPropertyType() function. If it returns the string 'BitFingerprint' or 'SciTegic.value.BitsetValue', then it is a bitset.)

These functions are most efficient for bitsets, although some can be called on properties that contain other data types. In this case, a copy of the contents of the property is converted into a bitset, and the operation is performed using that copy. This is less efficient, as the conversion is performed each time a bitset operation is called. For example, if a property contained the string value '1 2 3', then a bitset operation could automatically create a bitset of size 3 with bits 1, 2, and 3 on. For efficiency, it is best to convert the property to a bitset using the ChangePropertyType() function.

Bitset Function Name/Prototype Description Example

BitsetAnd

Bitset BitsetAnd(Bitset bsvar1, Bitset bsvar2)
Performs a logical AND operation on the two bitsets and returns a bitset with the new value. This new bitset contains the set of all bits that are "on" in both of the argument bitsets. If one of the bitsets has fewer bits then the other, it is "padded" with off bits up to the size of the larger one. The returned bitset is of this size.
andBitset := BitsetAnd(bsvar1, bsvar2);

Creates a new property andBitset, which is the logical AND of the bits in bitsets bsvar1 and bsvar2.

BitsetAndNot

Bitset BitsetAndNot(Bitset bsvar1, Bitset bsvar2)
Performs a logical ANDNOT operation on the two bitsets and returns a bitset with the new value, which contains the set of all bits that are "on" in the first argument, and "off" in the second one. If one of the bitsets has fewer bits than the other, it is padded with "off" bits that match the size of the larger one. The returned bitset is of this size.
andNotBitset := BitsetAndNot(bsvar1, bsvar2);

Creates a new property andNotBitset, which is the logical ANDNOT of the bits in bitsets bsvar1 and bsvar2.

BitsetClear

None BitsetClear(Bitset bsvarname)
Sets all "on" bits in the given bitset property to "off". (This is also the behavior of the Clear function when called on a bitset property.)
BitsetClear(bsvar);

Sets all bits in the bitset bsvar to "off".

BitsetCount

Number BitsetCount(Bitset bsvarname)
Gets the total number of "on" bits in the given bitset property. (This is also the behavior of the NumValues function when called on a bitset property.)
numBitsOn := BitsetCount(bsvar);

Gets the number of "on" bits in the bitset bsvar.

BitsetCreate

Bitset BitsetCreate(Number size)
Returns a bitset containing the given number of bits. All bits are initially "off".
MyBitset := BitsetCreate(1024);

Creates a bitset with 1024 bits.

BitsetFlipAll

None BitsetFlipAll(Bitset bsvarname)
Sets the "on" bits in the given bitset property to "off'; sets the "off" bits to "on".
BitsetFlipAll(bsvar);

Flips the "on/off" values for all bits in the bitset bsvar.

BitsetNext

Number BitsetNext(Bitset bsvar1, Number indexvar)
Returns the index of the next "on" bit after the given bit index. To find the first "on" bit, pass in an index of 0. If the value returned is 0, there is no "on" bit after the given index. The index must be in the range from 0 to the size of the bitset.
next := BitsetNext(bsvar1, 55);

Returns the index of the next "on" bit after the 55th bit.

BitsetOff

None BitsetOff(Bitset bsvar1, Number indexvar)
Sets the bit specified by the index to "off". The index must be in the range from 1 to the size of the bitset. If the property is not a bitset, it is converted into a bitset.
BitsetOff(bsvar1, 55);

Sets the 55th bit to "off" if it is "on".

BitsetOn

None BitsetOn(Bitset bsvar1, Number indexvar)
Sets the bit specified by the index to "on". The index must range from 1 to the size of the bitset. If the property is not a bitset, it is converted into one.
BitsetOn(bsvar1, 55);

Sets the 55th bit to "on" if it is "off".

BitsetOr

Bitset BitsetOr(Bitset bsvar1, Bitset bsvar2)
Performs a logical OR operation on the two bitsets, and returns a bitset with the new value, which contains the set of all bits that are "on" in either of the argument bitsets. If one of the bitsets has fewer bits than the other, it is padded with "off" bits to the size of the larger one. The returned bitset is of this size.
orBitset := BitsetOr(bsvar1, bsvar2);

Creates a new property orBitset which is the logical OR of the bits in bitsets bsvar1 and bsvar2.

BitsetResize

None BitsetResize(Bitset bsvarname, Number numbits)
Sets the total number of bits in the given bitset property. If the number is larger than the current number of bits, the additional bits are set to "off". If the property is not already stored as a bitset, a conversion is performed. (This is also the behavior of the Resize function when called on a bitset property.)
BitsetResize(bsvar, 1024);

Sets the number of bits in the bitset to 1024.

BitsetSize

Number BitsetSize(Bitset bsvar)
Returns the total number of bits; either "on" or "off" in the given bitset property.
numBits := BitsetSize(bsvarname);

The property bsvarname is considered a bitset. Returns the number of bits.

BitsetTest

Boolean BitsetTest(Bitset bsvar1, Number indexvar)
Tests if the bit specified by the index is "on". The index must range from 1 to the size of the bitset. If the bit is "on" it returns True, otherwise False.
is55ON := BitsetTest(bsvar1, 55);

Creates a new property is55On, which is True if the 55th bit is "on" and False if it is "off".