返回二进制翻转后的值

#include
#include
unsigned int reverse_bit(unsigned int value) {
	int i, j;
	int tmp1;
	int tmp2;
	for (i = 0, j = 31;i < j;i++, j--) {
		tmp1 =!!(value & 1 << i);
		tmp2 =!!(value & 1 << j);
		value &= ~(1 << i);
		value &= ~(1 << j);
		value |= tmp1 << j;
		value |= tmp2 >> j;
		

	}
	return value;
}
int main() {
	unsigned int n = 25;
	printf("%u", reverse_bit(n));
	system("pause");
	return 0;
}

你可能感兴趣的:(返回二进制翻转后的值)