ObjectScript Reference
$BITFIND


$BITFIND(bitstring,bitvalue,position,direction)
An expression that evaluates to a bitstring. Can be a variable of any type, 

The value (0 or 1) to search for within the bitstring.  
// Set a to [0,0,1,1,0] 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 // Find first 1 bit within a WRITE !,$BITFIND(a,1)
// Set a to [0,0,1,1,0] 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 // Find first 1 bit from position 3 WRITE !,"found a 1 at bit position:",$BITFIND(a,1,3) // Find first 0 bit from position 3 WRITE !,"found a 0 at bit position:",$BITFIND(a,0,3)
// Set a to [0,0,1,1,0] 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 !,"found a 1 at bit position:",$BITFIND(a,1,99,1) WRITE !,"found a 0 at bit position:",$BITFIND(a,0,99,1)
// Set a to [0,0,1,1,0] 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 SET pos=0 WRITE !,"Bit positions with value 1: " FOR { SET pos=$BITFIND(a,1,pos+1) QUIT:'pos WRITE pos,", " } WRITE !,"Bit positions with value 0: " FOR { SET pos=$BITFIND(a,0,pos+1) QUIT:'pos WRITE pos,", " }
SET x=$RANDOM(65536) FOR i=1:1:16 {WRITE $BIT($FACTOR(x),i) } WRITE !,"The first 1 bit is at position ",$BITFIND($FACTOR(x),1)
Content for this page loaded from RCOS_fbitfind.xml on 20180623 08:43:39
