11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Caché</strong> <strong>ObjectScript</strong> FunctionsThe following example shows the results of specifying a length greater than the input bitstring.The string is zero-filled before the logic operation is performed.// Set a to [1,1]SET $BIT(a,1) = 1SET $BIT(a,2) = 1WRITE !,"bitstring a=",$BIT(a,1),$BIT(a,2)SET c = $BITLOGIC(~a,7)WRITE !,"~a (length 7)="WRITE $BIT(c,1),$BIT(c,2),$BIT(c,3),$BIT(c,4)WRITE $BIT(c,5),$BIT(c,6),$BIT(c,7),$BIT(c,8)Here the one's complement (~) of 11 is 0011111. Bits 3 through 7 were set to zero beforethe ~ operation was performed. This example also displays an eighth bit, which is beyondthe specified string length and thus unaffected by the $BITLOGIC operation. It is, of course,displayed as 0.The following example shows the results of specifying a length less than the input bitstring.The bitstring is truncated to the specified length before logical operations are performed. Allbits beyond the specified length default to 0.// Set a to [1,1,1]SET $BIT(a,1) = 1SET $BIT(a,2) = 1SET $BIT(a,3) = 1WRITE !,"bitstring a=",$BIT(a,1),$BIT(a,2),$BIT(a,3)SET c = $BITLOGIC(a,2)WRITE !," a (length 2)="WRITE $BIT(c,1),$BIT(c,2),$BIT(c,3),$BIT(c,4)SET c = $BITLOGIC(~a,2)WRITE !,"~a (length 2)="WRITE $BIT(c,1),$BIT(c,2),$BIT(c,3),$BIT(c,4)The following example shows that when length is not specified, it defaults to the length ofthe longest bitstring. Shorter bitstrings are zero-filled before the logical operation is performed.// Set a to [1,1,1]SET $BIT(a,1) = 1SET $BIT(a,2) = 1SET $BIT(a,3) = 1// Set b to [1,1]SET $BIT(b,1) = 1SET $BIT(b,2) = 1SET c = $BITLOGIC(a&~b)WRITE !," a&~b="WRITE $BIT(c,1),$BIT(c,2),$BIT(c,3)SET c = $BITLOGIC(a&~b,3)WRITE !,"a&~b,3="WRITE $BIT(c,1),$BIT(c,2),$BIT(c,3)Here the two $BITLOGIC operations (with and without a length argument) both return thesame value: 001.190 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

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

Saved successfully!

Ooh no, something went wrong!