Chinaunix首页 | 论坛 | 博客
  • 博客访问: 98053
  • 博文数量: 13
  • 博客积分: 1404
  • 博客等级: 上尉
  • 技术积分: 145
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-01 12:51
文章分类

全部博文(13)

文章存档

2014年(4)

2013年(3)

2012年(3)

2011年(1)

2009年(2)

我的朋友

分类: C/C++

2014-06-21 16:59:56

Reversing the bits in an integer x is somewhat painful, but here's a SWAR algorithm for a 32-bit value:

unsigned int
reverse(register unsigned int x)
{
	x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
	x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
	x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
	x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));
	return((x >> 16) | (x << 16));

}
阅读(2020) | 评论(0) | 转发(0) |
0

上一篇:linux获取程序的绝对路径

下一篇:没有了

给主人留下些什么吧!~~