Caché ObjectScript Reference
$BITCOUNT


Returns the number of bits in a bitstring.
Synopsis
$BITCOUNT(bitstring,bitvalue)
Parameters
Description
The
$BITCOUNT function counts the number of bits within a bitstring. A bitstring is an encoded string which is interpreted by the system as a series of bits. You can create a bitstring using
$BIT or
$BITLOGIC.
The maximum bitstring length is 262,104 bits (32763 x 8).
Examples
SET $BIT(a,1) = 0
SET $BIT(a,2) = 0
SET $BIT(a,3) = 1
SET $BIT(a,4) = 1
SET $BIT(a,5) = 0
WRITE !,$BITCOUNT(a)
SET $BIT(a,1) = 0
SET $BIT(a,2) = 0
SET $BIT(a,3) = 1
SET $BIT(a,4) = 1
SET $BIT(a,5) = 0
WRITE !,"number of zero bits:",$BITCOUNT(a,0)
WRITE !,"number of one bits: ",$BITCOUNT(a,1)
The following example returns the number of 1 bits in a random 16bit bitstring generated by
$FACTOR:
SET x=$RANDOM(65536)
FOR i=1:1:16 {WRITE $BIT($FACTOR(x),i) }
WRITE !,"Number of 1 bits=",$BITCOUNT($FACTOR(x),1)
See Also