/*
  num.c
  Written by D'Arcy J.M. Cain
  darcy@druid.net

  Here is a little program which reads a number in and gives it back in
  binary, octal, hex and decimal forms. The input can be in decimal, octal
  (leading 0) or hex (leading 0x.)  Note that this is highly simplified.

  Note that cain/stdio is a wrapper around the real stdio.h that prototypes
  getline(3).
*/

#include	<stdlib.h>
#include	<cain/stdio.h>

int
main(void)
{
	char		*p;
	long long	k;
	long long	v, x;

	while ((p = getline(stdin, 0)) != NULL)
	{
		v = (*p == '-') ? strtoll(p, NULL, 0) : strtoull(p, NULL, 0);

		for (x = v, k = 0; k < 64; k++)
		{
			putchar(x & 0x8000000000000000ll ? '1' : '0');
			x <<= 1;
		}

		printf("b\n    %024llo 0x%016llx %20lld\n", v, v, v);
	}

	return(0);
}
