Reverse the bit in a integer 倒置整形数的bit

前端之家收集整理的这篇文章主要介绍了Reverse the bit in a integer 倒置整形数的bit前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <iostream>

unsigned int reverseInt(int val)
{
	unsigned int res = 0;

	for(int i = 0; i < 32; i++)
	{
		res <<= 1;
		res |= (val & 1);
		val >>= 1;
	}

	return res;
};


int main()
{
	unsigned int res = reverseInt(1);

	return 0;
}
原文链接:https://www.f2er.com/javaschema/286714.html

猜你在找的设计模式相关文章