2011年2月6日星期日

<转>What is the minimum number instructions required to swap Odd and even bits in an uinteger

well ths soultion will be like
1) let the number be A = 10101111
2) A1 = A & 10101010 = 10101010
3) A2 = A & 01010101 = 00000101
4) A1 = A1 >> 1 = 01010101
5) A2 = A2 << 1 = 00001010
6) Answer = A1 | A2 = 01011111
so u require 5 instructions

没有评论:

发表评论