/* Convert base 36 strings to hex
 * 2009 Dave Ackley
 * This code is placed in the public domain.
 */
#include <stdio.h>              /* For printf */
#include <stdlib.h>             /* For strtol */
#include <errno.h>              /* For errno */
#include <limits.h>             /* For LONG_MAX */

int main(int argc, char ** argv) {
  char * endptr;
  unsigned int val;

  if (argc != 2) {
    fprintf(stderr,"%s base36string\n",argv[0]);
    return 1;
  }

  val = strtol(argv[1],&endptr,36);

  if (*endptr != 0)
    return 2;

  if (val == LONG_MAX && errno != 0) 
    return 3;

  printf("0x%08x\n",val);
  return 0;
}
