d2x.c
by Dave Aronson
/* decimal to hex converter */
/* COPYRIGHT 1998, David J. Aronson */
/* License freely granted for all non-commercial use */
/* All other rights reserved */
#include <stdio.h>
#include <stdlib.h>
unsigned long atoul (char *s);
void main (int argc, char *argv[])
{
int argNum;
/* for each arg, print it plus translation */
for (argNum = 1; argNum < argc; argNum++)
{
printf ("%s (dec) = %lx (hex)\n", argv[i], atoul (argv[i]));
}
}
/* atol is SIGNED, dagnabit! */
unsigned long atoul (char *s)
{
char* c;
unsigned long l = 0;
/* for each char, multiply total by ten and add digit value */
for (c = s; *c; c++) l = l * 10 + (*c - '0');
return l;
}