How to reverse bits

Pages: 12
My five cents (which I have not:) )

1
2
3
4
5
6
7
8
9
10
11
unsigned int ReverseBits( unsigned int x )
{
	unsigned int y = 0;

	for ( int n = std::numeric_limits<unsigned int>::digits - 1; x; x >>= 1, --n )
	{
		if ( x & 1 ) y |= 1 << n;
	}

	return y;
}
Last edited on
Thanks for all advice!!!
Topic archived. No new replies allowed.
Pages: 12