/* * GENESIS Copyright (c) 1986, 1990 by John J. Grefenstette * This program may be freely copied for educational * and research purposes. All other rights reserved. * * file: convert.c * * purpose: functions that translate between various representations * * modified: 16 apr 86 * 15 sep 90: translations for floating point representation */ #include "extern.h" static char BIT[CHARSIZE] ={ '\200', '\100', '\040', '\020', '\010', '\004', '\002', '\001'}; /* Itoc and Ctoi translate ints to strings and vice versa */ unsigned long int Ctoi(instring, length) char *instring; /* string representation */ int length; /* length of instring */ { register int i; /* loop control */ unsigned long n; /* accumulator for return value */ n = (unsigned long) 0; for (i=0; i=0; i--) { outstring[i] = '0' + (n & 1); n >>= 1; } } /* Pack and Unpack translate between strings and (packed) bit arrays */ Pack(instring, outstring, length) char *instring; /* string representation */ char *outstring; /* packed representation of instring */ int length; /* length of instring */ { static firstflag = 1 ; static full; /* number of fully used bytes in outstring */ static slop; /* number of bits used in outstring's last byte */ register i,j; /* loop control */ if (firstflag) { full = length / CHARSIZE; slop = length % CHARSIZE; firstflag = 0; } for (i=0; i