/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>

int indec()
{
  int res;
  printf("Enter decimal: ");
  scanf("%d",&res);
  return res;
}

int inhex()
{
  int res;
  printf("Enter hexadecimal: ");
  scanf("%X",&res);
  return res;
}

int inbin()
{
  int res,ix;
  char line[34];
  printf("Enter binary: ");
  scanf("%s",line),
  ix=0;
  res = 0;
  while(line[ix]!='\0')
  {
     res = res * 2 + (line[ix]=='1' ? 1 : 0);
     ix++;
  }
  return res;
}

void outdec(int v)
{
   printf("decimal = %d\n",v);
}

void outhex(int v)
{
   printf("hexadecimal = %X\n",v);
}

void outbin(int v)
{
   int i;
   printf("binary = ");
   for(i=0;i<sizeof(int)*8;i++)
   {
      printf("%d",(v >> (sizeof(int)*8 - i - 1)) & 1);
   }
   printf("\n");
}

int main()
{
   int v;
   v = indec();
   outdec(v);
   outhex(v);
   outbin(v);
   v = inhex();
   outdec(v);
   outhex(v);
   outbin(v);
   v = inbin();
   outdec(v);
   outhex(v);
   outbin(v);
   return 0;
}
