/*
   reverse.c
   -------------------
   Written by d1s4st3r


   http://xoomer.alice.it/mental_insomnia/
   http://d1s4st3r.blogspot.com/
   http://d1s4st3r.deviantart.com/


   To compile on GNU/Linux or a generic UNIX system:
      gcc -o reverse reverse.c
*/


#include <stdio.h>
#include <stdlib.h>
#include <math.h>


#define		BITS		7


int power(int a, int b)
{
	if (b==0)
		return 1;

	return a*power(a, b-1);
}


int reverse(int n)
{
	register int i;
	register int bit;
	int r = 0;

	for (i=BITS; i>=0; i--)
	{
		bit = 1&(n>>i);
		r += bit*power(2, (BITS-i));
	}

	return r;
}


int main()
{
	int i;

	for (i=0; i<256; i++)
		printf("%d\t%d\n", i, reverse(i));

	return 0;
}

