home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
VRAC
/
DDMC100.ZIP
/
DDMC.C
next >
Wrap
C/C++ Source or Header
|
1993-09-08
|
5KB
|
198 lines
/* ddmc.c */
/****************************************************************************
Doug Deep's MegaNum Converter ■ version 1
Freeware from Duane Paulson. A "MegaNum" is what the RIPscrip people call a
base 36 number. These are used in RIPscrips to allow data to be transmitted
in a compact format. Unfortunately, base-36 conversions are far from
intuitive, and in fact can lead to nightmare situations, as in Flag 1 of
the Button Descriptor, which is a 4 digit MegaNum, bitmapped! In order to
ease the pain of dealing with MegaNums, this program is presented. It
accepts input in Binary, Decimal, Hexadecimal, or MegaNum format, then
translates and displays the values for each of these for base-number systems.
[RIPscrip is a trademark of TeleGrafix Communications, Inc., which had nothing
to do with the making of this program.]
Contacting the Author (Duane Paulson):
o Leave a message to DUANE PAULSON on the Main Board of The Kandy Shack BBS
(714)636-2662 -- Garden Grove, CA.
o Or, you might try leaving a message to DUANE PAULSON in the ILink Shareware
Conference.
o ci922@cleveland.freenet.edu (Duane A. Paulson)
****************************************************************************/
/****************************************************************************
HISTORY:
1.00 09/08/93:
Initial release of ddmc.
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFSIZE 1023
char buf[BUFSIZE+1];
char bindigs[]="01";
char decdigs[]="0123456789";
char hexdigs[]="0123456789ABCDEF";
char meganums[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char binnums[16][5]={
"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" };
char hexs[7];
char binprompt[]="Binary";
char maxbinval[]="1 1001 1010 0000 1111 1111";
int maxbindigits=21;
char decprompt[]="Decimal";
char maxdecval[]="1,679,615";
int maxdecdigits=7;
char hexprompt[]="Hexadecimal";
char maxhexval[]="19 A0 FF";
int maxhexdigits=6;
char megprompt[]="MegaNum";
char maxmegval[]="ZZZZ";
int maxmegdigits=4;
main()
{
long d, s;
int e, maxdigs, base, nogood;
char *b, *digits, *maxval, *prompt, *q;
printf("Doug Deep's MegaNum Converter ■ version 1.00 ■ 09/08/93\n\n");
printf("Freeware from Duane Paulson. A \"MegaNum\" is what the RIPscrip people call a\n");
printf("base 36 number. These are used in RIPscrips to allow data to be transmitted\n");
printf("in a compact format. Unfortunately, base-36 conversions are far from\n");
printf("intuitive, and in fact can lead to nightmare situations, as in Flag 1 of\n");
printf("the Button Descriptor, which is a 4 digit MegaNum, bitmapped! In order to\n");
printf("ease the pain of dealing with MegaNums, this program is presented. It\n");
printf("accepts input in Binary, Decimal, Hexadecimal, or MegaNum format, then\n");
printf("translates and displays the values for each of these for base-number systems.\n\n");
printf("[RIPscrip is a trademark of TeleGrafix Communications, Inc., which had nothing\n");
printf("to do with the making of this program.]\n");
while(1)
{
*buf='z';
while(strchr("bdhm\n", *buf)==NULL)
{
printf("\nSelect format for input\n");
printf("\tB)inary. . . . .base 2\n");
printf("\tD)ecimal . . . .base 10\n");
printf("\tH)exadecimal . .base 16\n");
printf("\tM)egaNum . . . .base 36\n");
printf("Enter Selection (CR alone exits):");
fgets(buf, 3, stdin);
*buf=(char)tolower(*buf);
}
if(*buf=='\n')
exit(0);
if(*buf=='b')
{
base=2;
prompt=binprompt;
digits=bindigs;
maxval=maxbinval;
maxdigs=maxbindigits;
}
if(*buf=='d')
{
base=10;
prompt=decprompt;
digits=decdigs;
maxval=maxdecval;
maxdigs=maxdecdigits;
}
if(*buf=='h')
{
base=16;
prompt=hexprompt;
digits=hexdigs;
maxval=maxhexval;
maxdigs=maxhexdigits;
}
if(*buf=='m')
{
base=36;
prompt=megprompt;
digits=meganums;
maxval=maxmegval;
maxdigs=maxmegdigits;
}
while(1)
{
printf("\n%s value to convert (CR alone exits): ", prompt);
fgets(buf, BUFSIZE, stdin);
if(*buf=='\n')
break;
if((s=strlen(buf))>(maxdigs+1))
{
fprintf(stderr, "Number out of range (0 - %s)\n", maxval);
continue;
}
strupr(buf);
d=0;
nogood=0;
for(b=buf; *b!='\n'; b++)
{
if((q=strchr(digits, *b))==NULL)
{
printf("Illegal digit `%c' (ascii %d)\n", *b, *b);
nogood++;
}
d*=base;
d+=(long)(q-digits);
}
if(nogood)
continue;
if(d>1679615L)
{
fprintf(stderr, "Number out of range (0 - %s)\n", maxval);
continue;
}
printf("dec: %ld\n", d);
sprintf(hexs, "%lX\n", d);
printf("hex: %s", hexs);
printf("bin: ");
for(b=hexs; *b!='\n'; b++)
printf("%s ", binnums[strchr(hexdigs, *b)-hexdigs]);
printf("\n");
printf("meg: ");
e=(int)(d/46656L);
d%=46656L;
printf("%c", meganums[e]);
e=(int)(d/1296L);
d%=1296L;
printf("%c", meganums[e]);
e=(int)(d/36L);
d%=36L;
printf("%c%c\n", meganums[e], meganums[d]);
}
}
}
/* end ddmc.c */