Category : C Source Code
Archive   : SNIP1292.ZIP
Filename : BASCNVRT.C

 
Output of file : BASCNVRT.C contained in archive : SNIP1292.ZIP
/*
** BASCNVRT.C - Convert between number bases
**
** public domain demo by Bob Stout
*/

#include
#ifdef TEST
#include
#endif

/*
** Calling parameters: 1 - Number string to be converted
** 2 - Buffer for the converted output
** 3 - Radix (base) of the input
** 4 - Radix of the output
**
** Returns: Pointer to converted output
*/

char *base_convert(const char *in, char *out, int rin, int rout)
{
long n;
char *dummy;

n = strtol(in, &dummy, rin);
return ltoa(n, out, rout);
}

#ifdef TEST

int main(int argc, char *argv[])
{
int rin, rout;
char buf[40];

if (4 > argc)
{
puts("Usage: BASCNVRT ");
return(-1);
}
rin = atoi(argv[2]);
rout = atoi(argv[3]);
printf("%s (base %d) = %s (base %d)\n", argv[1], rin,
base_convert((const char *)argv[1], buf, rin, rout), rout);
return 0;
}

#endif


  3 Responses to “Category : C Source Code
Archive   : SNIP1292.ZIP
Filename : BASCNVRT.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/