ObjectScript Reference
$BITCOUNT


$BITCOUNT(bitstring,bitvalue)
bitstring  An expression that evaluates to a bitstring. Can be a variable of any type, $FACTOR, a userdefined function, or an oref.prop, ..prop, or i%prop (instance variable) property reference. 
bitvalue  Optional — The value (0 or 1) to count within the bitstring. 
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)
SET x=$RANDOM(65536) FOR i=1:1:16 {WRITE $BIT($FACTOR(x),i) } WRITE !,"Number of 1 bits=",$BITCOUNT($FACTOR(x),1)