/*  This program translates the FOVC to allow you, yes you to follow
    cellular conversations on you motorola.  This program is trivial 
    and simply automates some easy math.  Read the Motorola Bible
    for more details.                   

                                              Ho' DeFone/MHP      */
#include <stdio.h>
#include <strings.h>

char *hextobin(char *farmer,char pig[14])
{
  int x;

  for (x=0;farmer[x]!=0;x++)
  {
   switch (farmer[x])
   {
       case '0': strcat(pig,"0000"); break;
       case '1': strcat(pig,"0001"); break;
       case '2': strcat(pig,"0010"); break;
       case '3': strcat(pig,"0011"); break;
       case '4': strcat(pig,"0100"); break;
       case '5': strcat(pig,"0101"); break;
       case '6': strcat(pig,"0110"); break;
       case '7': strcat(pig,"0111"); break;
       case '8': strcat(pig,"1000"); break;
       case '9': strcat(pig,"1001"); break;
       case 'a': strcat(pig,"1010"); break;
       case 'b': strcat(pig,"1011"); break;
       case 'c': strcat(pig,"1100"); break;
       case 'd': strcat(pig,"1101"); break;
       case 'e': strcat(pig,"1110"); break;
       case 'f': strcat(pig,"1111"); break;
   }
}
 return pig+2; /* returns a pointer which strips 2 MSB off of the binary # */ 
}
void main(int argc, char *argv[])
{
   char pork[14],*farm;
   long int turkey;

   if (argc != 2 || (strlen(argv[1])!=3)) {
       fprintf(stderr,"fovc: must supply a 3 digit hex number\n"); 
       exit(0);
   }
   farm=hextobin(argv[1],pork);
   turkey=strtol(farm,(char **) NULL, 2);
   printf("%ld\n",turkey);
}

