Reverse the bit of an interger (assume it has 32-bit)

Go down

Reverse the bit of an interger (assume it has 32-bit)

Post  viterbi on Tue Sep 13, 2011 9:58 am

1____unsigned int reverse_bit(unsigned int x) {
2__________x = (x & 0x0000ffff) << 16 | (x & 0xffff0000) >> 16;
3__________x = (x & 0x00ff00ff) << 8 | (x & 0xff00ff00) >> 8;
4__________x = (x & 0x0f0f0f0f) << 4 | (x & 0xf0f0f0f0) >> 4;
5__________x = (x & 0x33333333) << 2 | (x & 0xcccccccc) >> 2;
6__________x = (x & 0x55555555) << 1 | (x & 0xaaaaaaaa) >> 1;
7____}

viterbi

Posts : 32
Join date : 2011-09-03

View user profile

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum