/* @file: asciibin.c @author: Matt Bradford @date: 16 Aug 2005 @desc: encodes and decodes strings to a binary representation and back. */ #include #include #ifndef ONE_CHAR #define ONE_CHAR '=' #endif #ifndef ZERO_CHAR #define ZERO_CHAR '-' #endif /* Given an integer , will print out the binary representation of that character using ONE_CHAR and ZERO_CHAR */ void printBinString(int x) { int n; for(n=0; n<8; n++) { if((x & 0x80) !=0) { printf("%c",ONE_CHAR); } else { printf("%c",ZERO_CHAR); } x = x<<1; } }; /* Encode a string. If not quoted, spaces will be inserted automatically between parameters. */ int encode(int argc, char *argv[]) { /* n holds the position in the current byte */ int i,j,n; /* x is the current character being translated */ char x; for (i=2; i