Examples of $ZBIT Functions

Example:

    ZCRC(X)
    NEW R,I,J,B,X1,K
    SET R=$ZBITSTR(8,0)
    FOR I=1:1:$L(X) S R=$ZBITXOR(R,$$BITIN($A(X,I)))
    QUIT $$BITOUT(R)
    ;CONVERT A BYTE TO A BIT STRING
    
    BITIN(X)
    SET X1=$ZBITSTR(8,0)
    FOR J=1:1:8 S B=X#2,X=X\2 i B s X1=$ZBITSET(X1,J,1)
    QUIT X1
    ; CONVERT A BITSTRING TO A NUMBER
    
    BITOUT(X)
    SET X1=0
    FOR K=1:1:8 I $ZBITGET(X,K) S 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.

While this example illustrates the use of several of the $ZBIT functions, the following example produces identical results if you need to code the function illustrated above for production.

    ZCRC(X)
    NEW R,I,J,B,X1,K
    SET R=$ZBITSTR(8,0)
    FOR I=1:1:$L(X) S R=$ZBITXOR(R,$C(0)_$E(X,I))
    QUIT $A(R,2)
    

This example illustrates the use of $C to specify the number of invalid bits that exist at the end of the character string. In this case there are zero invalid bits.