/* HEX.C translates the standard input into hexadecimal notation and sends * the result to standard output. * Usage: hex < foo.exe > foo.hex * Christine M. Gianone, CUCCA, October 1986 * Modified Feb 89 to work right with Microsoft C on the PC. */ #include /* For EOF symbol */ #ifdef MSDOS #include /* For MS-DOS O_BINARY symbol */ #endif char h[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; unsigned int c; int ctr = 0; char a, b; main() { #ifdef MSDOS setmode(fileno(stdin),O_BINARY); /* To avoid DOS text-mode conversions */ #endif while ((c = getchar()) != EOF) { b = c & 0xF; /* Get low 4 bits */ a = c / 16; /* and high 4 bits */ putchar(h[a]); /* Hexify and output them */ putchar(h[b]); ctr += 2; /* Break lines every 72 characters */ if (ctr == 72) { putchar('\n'); ctr = 0; } } putchar('\n'); /* Terminate final line */ }