码迷,mamicode.com
首页 > 编程语言 > 详细

交换二进制奇偶位(算法)

时间:2015-03-14 16:57:40      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

Write a program to swap odd and even bits in an integer with as few instructions as possible.

public static int swapOddEvenBits(int x)
{
	return ( (( x & 0xaaaaaaaa) >> 1 | (x & 0x55555555) << 1) );
}


交换二进制奇偶位(算法)

标签:

原文地址:http://blog.csdn.net/xiaogaokuaixiazai/article/details/44260769

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!