[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ZEROINSERT()
 Inserts a 0-bit after every fifth 1-bit
------------------------------------------------------------------------------
 Syntax

     ZEROINSERT(<cString>) --> cDataBlock

 Argument

     <cString>  Designates any character string in which you choose to
     insert a 0-bit.

 Returns

     The function returns a character string with the 0-bit inserted.

 Description

     This function has been incorporated to allow simplified programming of
     data transmission protocols to the CCITT specification.  CCITT
     determines that each data block has a start and a stop flag, like
     "01111110".  To ensure that the flag bit pattern doesn't appear within
     the data, a 0-bit is inserted after every fifth 1-bit.  These explicit
     flags allow a transfer protocol to resynchronize itself more quickly if
     a transmission error occurs.  For example, this process is implemented
     by ISDN or X.25 networks.

 Note

     .  Due to the inserted bit, the character string that is returned
        is longer than the character string that is transmitted.  Length
        increases a maximum of 20%, which can be calculated as follows:

           nMaxLen = LEN(cString) + CEILING(LEN(cString)/5)

 Examples

     .  For any five bytes of the original string, a maximum of one
        additional byte can arrive as a result.  This example tests, if there
        is enough available free memory, for the resulting string:

        cCharacter := CHR(CTON("11111111", 2)
        cString    := REPLICATE(cCharacter, 6)
        nMaxLen    := LEN(cString) + CEILING(LEN(cString) /5)
                                                        //Here: 8

        IF nMaxLen  < MEMORY(1) * 1024 - 100
           cString  := ZEROINSERT(cString)
        ENDIF

     .  This example shows the construction of a typical data block:

        cFlag   :=  CHR(CTON("01111110", 2))            // According to
                                                        // CCITT
        cData   :=  "Also transmit ????!"
        CRC    :=  COM_CRC(cData)

        cBlock  := cData + SUBSTR(L2BIN(CRC), 1, 2)     // Add CRC to
                                                        // string
        cBlock  := ZEROINSERT(cBlock)
        cBlock  := cFlag + cBlock + cFlag


See Also: ZEROREMOVE() COM_CRC()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson