home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / unix_c / utils / bintnx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-21  |  1.0 KB  |  52 lines

  1. /***********************************************************************
  2. Convert a TOPS-20 file transferred in FTP "binary" mode to "tenex" mode.
  3. In "binary" mode, we have 2 36-bit words in 9 8-bit bytes.  In "tenex"
  4. mode, we want the top 32 bits of each 36-bit group, giving 8 8-bit bytes.
  5.  
  6. Who knows what FTP did if the file had an odd number of 36-bit words.
  7.  
  8. [08-Oct-87]
  9.  
  10. ***********************************************************************/
  11.  
  12. #include <stdio.h>
  13.  
  14. main()
  15. {
  16.     int c,d;
  17.  
  18.     for (;;)
  19.     {
  20.         c = getchar();
  21.     if (c == EOF)
  22.         break;
  23.         putchar(c);            /* 0..7 */
  24.     c = getchar();    putchar(c);    /* 8..15 */
  25.     c = getchar();    putchar(c);    /* 16..23 */
  26.     c = getchar();    putchar(c);    /* 24..31 */
  27.  
  28.     d = getchar();
  29.  
  30.     c = (d << 4);
  31.     d = getchar();
  32.     c |= 0xFF & (d >> 4);
  33.     putchar(c);            /* 4..11 */
  34.  
  35.     c = (d << 4);
  36.     d = getchar();
  37.     c |= 0xFF & (d >> 4);
  38.     putchar(c);            /* 12..19 */
  39.  
  40.     c = (d << 4);
  41.     d = getchar();
  42.     c |= 0xFF & (d >> 4);
  43.     putchar(c);            /* 20..27 */
  44.  
  45.     c = (d << 4);
  46.     d = getchar();
  47.     c |= 0xFF & (d >> 4);
  48.     putchar(c);            /* 28..36 */
  49.  
  50.     }
  51. }
  52.