|  |     Well, you can't convert just 'any old' ASCII string to RAD50 since
    the definition of RAD50 is a subset of the ASCII character set.
    It consists of the capital letters A through Z, the digits 0 through
    9, and few specials like dollar sign, dot, etc.  It was used to
    store things like filenames so the subset worked well.  If you can
    live with that I know I have the routines around somewhere to go
    in both directions RAD50 to ASCII and ASCII to RAD50.
 | 
|  | From Martin Minow's VAXLIB package:
Note that because `ascr50' defines `output' as an `int *', this will
only work as expected on a PDP-11.  I think it should be defined as
a `short *' and then it will work on both 16 and 32 bit machines.
Andy V
/*
 *
 *	ascr50(count, input, output)
 *	int		count;
 *	int		*output;
 *	char		*input;
 *
 * Description
 *
 *	Convert 'count' characters from ascii to Radix 50.  If there aren't a
 *	multiple of 3 characters, blanks are padded on the end.  The ascii
 *	string is moved to the output when finished.  The input and output
 *	areas may be the same since three input characters are read for
 *	every two bytes of output.
 */
struct table {
	char	low, high;
	int	magic;
};
struct table r50tab[] = {
	{ 'a',	'z',	-0140	},
	{ 'A',	'Z',	-0100	},
	{ '0',	'9',	-0022	},
	{ ' ',	' ',	-0040	},
	{ '$',	'$',	-0011	},
	{ '.',	'.',	-0022	},
	{ 0,	0, 	0	},
};
	
ascr50(count, input, output)
int		count;		/* Characters to convert		*/
char		*input;		/* Input string (ascii)			*/
int		*output;	/* Output vector (rad50)		*/
{
	register char		*wp;	/* Work area pointer		*/
	register int		byte;	/* Working byte			*/
	register struct table	*rp;	/* Rad50 table pointer		*/
	int			result;	/* Rad50 work -- gets value	*/
	char	work[3+1];		/* Gets next three bytes	*/
	for (;;) {
		work[0] = work[1] = work[2] = ' ';
		for (wp = work; --count >= 0;) {
			*wp++ = *input++;	/* Get one input byte	*/
			if (wp >= &work[3])
				break;
		}
		if (wp == work)
			return;			/* Nothing left to do	*/
		/*
		 * Convert 3 bytes (in word) to rad50
		 */
		result = 0;
		for (wp = work; wp < &work[3];) {
			byte = *wp++ & 0377;
			for (rp = r50tab; rp->low > 0; rp++) {
				if (byte >= rp->low && byte <= rp->high)
					break;
			}
			if (rp->low == 0)
				byte == 0;
			byte += rp->magic;
			result <<= 3;
			byte += result;
			result <<= 2;
			result += byte;
		}
		*output++ = result;
	}
}
/*
 *			r 5 0 t o a . c
 */
/*)LIBRARY
*/
#ifdef	DOCUMENTATION
title	r50toa	Convert Radix-50 to Ascii
Index		Convert radix-50 to Ascii
synopsis
	.s.nf
	r50toa(buff, r5vec, r5cnt);
	char		*buff;	/* Output text buffer	*/
	int		*r5vec;	/* Input rad50 buffer	*/
	int		r5cnt;	/* How many rad50 words	*/
	.s.f
description:
	Convert r5cnt words of radix 50 data to Ascii.  All letters
	will be in lower-case.  The output buffer will not be
	null-trailed, nor will blank fields be supressed.
bugs
#endif
#ifdef	pdp11
#define	SHORT	unsigned
#else
#define	SHORT	unsigned short
#endif
/*
 * Dave Conroy's algorithm
 */
/*
 * Convert `nr50' words worth of
 * RADIX 50 data, pointed to by the argument
 * r5vec, into `3*nr50' bytes of Ascii and
 * store the characters into the buffer
 * pointed to by the `cp' argument. The output
 * string is in lower case. The illegal code
 * in RADIX 50 is converted to a `?'.
 */
static char     ctable[] = {
	" abcdefghijklmnopqrstuvwxyz$.?0123456789"
};
r50toa(buffer, r5vec, r5cnt)
register char		*buffer;	/* Output buffer		*/
SHORT int		*r5vec;		/* Input rad50 vector		*/
int			r5cnt;		/* Number of 16-bit words to do	*/
/*
 * Convert r5cnt words of radix 50 data to Ascii.  All letters will be
 * in lower-case.  The output buffer will not be null-trailed, nor will
 * blank fields be supreessed.
 */
{
        register unsigned	r50;
        register char		*cp;
	while (--r5cnt >= 0) {
	    r50 = *r5vec++;
	    for (cp = ctable; r50 >= 03100; cp++) {
		r50 -= 03100;
	    }
	    *buffer++ = *cp;
	    for (cp = ctable; r50 >= 00050; cp++) {
		r50 -= 050;
	    }
	    *buffer++ = *cp;
	    *buffer++ = ctable[r50];
	}
}
 |