home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
archives
/
utils.tar.gz
/
utils.tar
/
hex.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-04-15
|
950b
|
35 lines
/* 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 <stdio.h> /* For EOF symbol */
#ifdef MSDOS
#include <fcntl.h> /* 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 */
}