The format for the $ZBITAND() function is:
$ZBITAND(expr1,expr2)
GTM>set BITSTRINGA=$zbitset($zbitset($zbitstr(8,0),2,1),8,1) ; The binary representation of A is 01000001 GTM>set BITSTRINGB=$zbitset($zbitset($zbitstr(8,0),2,1),7,1) ; The binary representation of B is 01000010 GTM>set BITSTRINGAB=$zbitand(BITSTRINGA,BITSTRINGB) GTM>for i=1:1:8 write $zbitget(BITSTRINGAB,i) 01000000
This examples uses $ZBITAND to perform a bitwise AND operation on A and B.
A = 01000001 B = 01000010 A bitwise AND B = 0100000
Returns the number of ON bits in a bit string.
The format for the $ZBITCOUNT function is:
$ZBITCOUNT(expr)
GTM>set BITSTRINGA=$ZBITSET($ZBITSET($ZBITSTR(8,0),2,1),8,1) ; The binary representation of A is 01000001 GTM>set BITSTRINGB=$zbitset($zbitset($zbitstr(8,0),2,1),7,1) ; The binary representation of B is 01000010 GTM>Set BITSTRINGC=$zbitor(BITSTRINGA,BITSTRINGB) ; A OR B=01000011 GTM>write $zbitcount(BITSTRINGA) 2 GTM>write $zbitcount(BITSTRINGB) 2 GTM>write $zbitcount(BITSTRINGC) 3 GTM>
This example displays the number of ON bits in BITSTRINGA, BITSTRINGB, and BITSTRINGC.
The format for the $ZBITFIND function is:
$ZBITFIND(expr,tvexpr[,intexpr])
Returns the value of a specified position in the bit string.
The format for the $ZBITGET function is:
$ZBITGET(expr,intexpr)
Returns a copy of the bit string with each input bit position inverted.
The format for the $ZBITNOT function is:
$ZBITNOT(expr)
The format for the $ZBITOR function is:
$ZBITOR(expr1,expr2)
GTM>set BITSTRINGA=$zbitset($zbitset($zbitstr(8,0),2,1),8,1) ; The binary representation of A is 01000001 GTM>set BITSTRINGB=$zbitset($zbitset($zbitstr(8,0),2,1),7,1) ; The binary representation of B is 01000010 GTM>set BITSTRINGC=$zbitor(BITSTRINGA,BITSTRINGB) ; A OR B=01000011 GTM>write BITSTRINGC C GTM>
This example displays the result of BITSTRINGA bitwise ORed with BITSTRINGB.
The format for the $ZBITSET function is:
$ZBITSET(expr,intexpr,tvexpr)
The format for the $ZBITXOR function is:
$ZBITXOR(expr1,expr2)
GTM>set BITSTRINGA=$zbitset($zbitset($zbitstr(8,0),2,1),8,1) ; The binary representation of A is 01000001 GTM>set BITSTRINGB=$zbitset($zbitset($zbitstr(8,0),2,1),7,1); The binary representation of B is 01000010 GTM>set BITSTRINGC=$zbitxor(BITSTRINGA,BITSTRINGB) ; A XOR B=00000011 GTM>for i=1:1:8 write $zbitget(BITSTRINGC,i) 00000011 GTM>
This example displays the result of the bitwise XOR of A and B.
ZCRC(X) new R,I,J,B,X1,K set R=$zbitstr(8,0) for I=1:1:$length(X) Set R=$zbitxor(R,$$bitin($A(X,I))) quit $$bitout(R) bitin(X) ;CONVERT A BYTE TO A BIT STRING set X1=$zbitstr(8,0) for J=1:1:8 set B=X#2,X=X\2 if B set X1=$zbitset(X1,J,1) quit X1 bitout(X) ; CONVERT A BITSTRING TO A NUMBER set X1=0 for K=1:1:8 I $zbitget(X,K) set X1=X1+(2**(K-1)) quit X1
This uses several $ZBIT functions to turn a character into a bit stream and return a coded value.
ZCRC(X) new R,I,J,B,X1,K set R=$zbitstr(8,0) for I=1:1:$length(X) Set R=$zbitxor(R,$char(0)_$extract(X,I)) quit $ascii(R,2)