11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

$BITLOGICNote:When $BITLOGIC is supplied more than two bitstring operands, it must createbitstring temporaries to hold the intermediate results. Under some extreme circumstances(many bitstrings and/or extremely large bitstrings), it can exhaust the spaceallocated to hold such temporaries. Bitstring pair operations do not have this limitation,and are thus preferable for large bitstring operations.The NOT (~) operator can be used as a unary operator (for example, ~A), or can be used incombination with other operators (for example, A&~B). It performs the one's complementoperation on a string, turning all 1's to 0's and all 0's to 1's. Multiple NOT operators can beused (for example, ~~~A).The length ArgumentIf length is not specified, it defaults to the length of the longest bitstring in bitstring_expression.If length is specified, it specifies the logical length of the resulting bitstring.• If length is larger than one or more of the bitstrings in bitstring_expression, those bitstringsare zero-filled to that length before bitstring logic operations are performed.• If length is smaller than one or more of the bitstrings in bitstring_expression, those bitstringsare truncated to that length before bitstring logic operations are performed.• If length is 0, a bitstring of length 0 (a null string) is returned.ExamplesThe following example creates some simple bitstrings and demonstrates the use of$BITLOGIC on them:// Set a to [1,1]SET $BIT(a,1) = 1SET $BIT(a,2) = 1// Set b to [0,1]SET $BIT(b,1) = 0SET $BIT(b,2) = 1WRITE !,"bitstring a=",$BIT(a,1),$BIT(a,2)WRITE !,"bitstring b=",$BIT(b,1),$BIT(b,2)SET c = $BITLOGIC(~b)WRITE !,"The one's complement of b=",$BIT(c,1),$BIT(c,2)// Find the intersection (AND) of a and bSET c = $BITLOGIC(a&b) // c should be [0,1]WRITE !,"The AND of a and b=",$BIT(c,1),$BIT(c,2)SET c = $BITLOGIC(a&~b) // c should be [1,0]WRITE !,"The AND of a and ~b=",$BIT(c,1),$BIT(c,2)// Find the union (OR) of a and bSET c = $BITLOGIC(a|b) // c should be [1,1]WRITE !,"The OR of a and b=",$BIT(c,1),$BIT(c,2)QUIT<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 189

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!