home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / kit / part01 / btoa / hexencode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.0 KB  |  52 lines

  1. /*
  2.  
  3.  #    #  ######  #    #  ######  #    #   ####    ####   #####   ######
  4.  #    #  #        #  #   #       ##   #  #    #  #    #  #    #  #
  5.  ######  #####     ##    #####   # #  #  #       #    #  #    #  #####
  6.  #    #  #         ##    #       #  # #  #       #    #  #    #  #        ###
  7.  #    #  #        #  #   #       #   ##  #    #  #    #  #    #  #        ###
  8.  #    #  ######  #    #  ######  #    #   ####    ####   #####   ######   ###
  9.  
  10.     stdout = hexa(stdin)
  11.  
  12.     R. Manfredi and E. Mogenet
  13. */
  14.  
  15. /*
  16.  * $Id: hexencode.c,v 2.0 91/02/19 15:49:33 ram Exp $
  17.  *
  18.  * $Log:    hexencode.c,v $
  19.  * Revision 2.0  91/02/19  15:49:33  ram
  20.  * Baseline for first official release.
  21.  * 
  22.  */
  23.  
  24. #include <stdio.h>
  25.  
  26. static char    rcs_id[] = "@(#)hexencode, stdout = hexa(stdin)";
  27.  
  28. #define QUARTET 0xF
  29. static char    hexa[] = "0123456789ABCDEF";
  30.  
  31. main()
  32. {
  33.     int    c;
  34.     int    jump;
  35.  
  36.  
  37.     jump = 0;
  38.     while (EOF != (c = getchar())) {
  39.         putchar(hexa[(c>>4) & QUARTET]);
  40.         putchar(hexa[c & QUARTET]);
  41.         jump += 2;
  42.         if ( jump > 75 ) {
  43.             putchar('\n');
  44.             jump = 0;
  45.         }
  46.     }
  47.     putchar('\n');
  48.     exit(0);
  49. }
  50.  
  51.  
  52.