C9TO8 - pack 9-bit bytes with 8-bit data to double words.

Usage:

B:
   seq = c9to8( input, inpos, inseq, nbytes, output );
C:
   int c9to8(const char *input, int inpos, int inseq,
              int nbytes, int *output);

Where:

input
is a pointer to the character string you want to pack.
inpos
is a character offset from the beginning of "input", indicating the first character you want to pack.
inseq
indicates a bit position within the output double words. The idea is that you specify 0 for "inseq" in the first call to C9TO8; for each subsequent call to C9TO8, you specify the return value from the previous call.
nbytes
is the number of input bytes to pack.
output
is a pointer to a region of memory where you want to store the converted data.
seq
indicates the bit position in the last double word where the packing left off. This should be passed as the "inseq" value in the next call to C9TO8.

Description:

C9TO8 packs a sequence of 9-bit bytes into a stream of 8 bit values. It does this by stripping the high order bit of each byte and concatenating the 8-bit values together. Input data like this is likely to have come from the TP.RD9 function.

Each 9 bytes of 8-bit data contains 72 bits of information that is packed into a double machine word as shown in the diagram below:

Input Character stream:
---------+---------+---------+---------
0aaaaaaaa 0bbbbbbbb 0cccccccc 0dddddddd
---------+---------+---------+---------
0eeeeeeee 0ffffffff 0gggggggg 0hhhhhhhh
---------+---------+---------+---------
0iiiiiiii
---------+
Output Double Word:
---------+---------+---------+---------
aaaaaaaab bbbbbbbcc ccccccddd dddddeeee
---------+---------+---------+---------
eeeefffff fffgggggg gghhhhhhh hiiiiiiii
---------+---------+---------+---------

The example below shows a typical way to use C9TO8 in unpacking data from tape:

bseq = 0;       /* initial position in input byte sequence */
for( word=0; nb && word < IO_BLKSIZE; word += wordinc ) {
    howmany = min( nb, blksz-byteno );
    howmany = min( howmany, (IO_BLKSIZE-word)/2*9-bseq );
    wordinc = (howmany+bseq)/9*2;
    bseq = c9to8(buffer,byteno,bseq,howmany,llinkbuf+word );
    if( (byteno+=howmany)>=blksz && fill_tar_buffer()==0 )
        error("Premature EOF on input restoring file %s.*n",
              hname );
    nb -= howmany;
}

See Also:

expl b lib c8to9

Copyright © 1996, Thinkage Ltd.