Path: blue.weeg.uiowa.edu!news.uiowa.edu!uunet!usc!elroy.jpl.nasa.gov!netline-fddi.jpl.nasa.gov!nntp-server.caltech.edu!toddpw
From: toddpw@mince.ugcs.caltech.edu (Todd P. Whitesel)
Newsgroups: comp.sys.apple2.programmer
Subject: Re: 6&2 encoding
Date: 14 Jul 1994 09:56:06 GMT
Organization: California Institute of Technology, Pasadena
Lines: 36
Message-ID: <30323m$nvl@gap.cco.caltech.edu>
References: <2vld92$pda@vixen.cso.uiuc.edu> <2vlpk1$kfv@gap.cco.caltech.edu> <CsoyEr.5vB@griffin.cuc.ab.ca>
NNTP-Posting-Host: mince.ugcs.caltech.edu
X-Newsreader: NN version 6.5.0 #14 (NOV)

dockery@griffin.cuc.ab.ca (Sean Dockery) writes:

>Actually, I really would like to know how BINSCII encodes if anyone could
>(and would) kindly provide a serious explanation.

If you understand the 6 & 2 encoding then you already understand 90% of the
tough part of BINSCII. All of the encoding in BINSCII is done as 3 byte
groups encoded into four characters, as if by the following C fragment:

BYTE bytes[3];      /* bytes to encode, in order */
char chars[4];      /* characters to output, in order */
char table[64] =
	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789()";
{
unsigned long bits = 0;
int i;

for (i=0; i<3; ++i)
        bits = (bits << 8) | bytes[i];
for (i=0; i<4; ++i)
        {
        chars[i] = table[bits & 0x3F];
        bits >>= 6;
        }
}

In this form the operation is more like a base conversion, where you are
taking a 3 byte number and converting it into a 4 "digit" base-64 number,
and then representing the base-64 "digits" with characters from the table.

Computationally this is the same as what the Disk ][ nibbleization code
does, except that the order of the bit shuffling is different, and the
"alphabet" is appropriate for the Disk ][ instead of email.

Todd Whitesel
toddpw @ ugcs.caltech.edu
