home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows NT Super Tune-Up Kit
/
PIE-WindowsNTSuperTuneUpKit-1997.iso
/
CONVERTR
/
CACODE
/
BYTESOUT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-13
|
1KB
|
67 lines
#include <extend.h>
int __b2int(char *, int);
char *__strsub(char *, char *, int, int);
CLIPPER Make_cByte(void) {
char *cBits = _parc(1);
int len = _parclen(1);
char BitTemp[7] = "";
char cBytesOut[5] = "";
cBytesOut[0] = (char)( 48+(__b2int(__strsub(cBits,BitTemp, 0,6),5)) );
cBytesOut[1] = (char)( 48+(__b2int(__strsub(cBits,BitTemp, 6,6),5)) );
cBytesOut[2] = (char)( 48+(__b2int(__strsub(cBits,BitTemp,12,6),5)) );
cBytesOut[3] = (char)( 48+(__b2int(__strsub(cBits,BitTemp,18,6),5)) );
cBytesOut[4] = '\0';
_retc(cBytesOut);
}
char *__strsub(char *bits, char *retval, int from, int digits ) {
int i;
int j;
for (i=from,j=0;j<digits;i++,j++) {
retval[j] = bits[i];
}
retval[6] = '\0';
return(retval);
}
int __b2int(char *num, int len) {
// len could be calculated, but it is faster if you just tell it how
// long the string is. REMEMBER the string length is 1 less than the
// actual length. C begins array indexing at 0, so a six character
// string is actually positions 0-5! Also, notice that the len var
// is checked until it reaches -1. We need the "0" position as it is
// the first character in the string.
int i = 0;
int j = 0;
for (j=0 ; len != -1 ; j++) {
if (num[len--] == '1')
i += __exponent(2,j);
}
return(i);
}