Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit1 are swapped, bit 2 and bit 3 are swapped, and so on).
方法: 先取偶数位,然后往左移1位, 再取奇数位,然后往右移动1位。 最后将得到的数,进行或运算。
时间复杂度: O(1) 空间复杂度: O(1) |
Algorithm_swap odd_even bit in an interger
最新推荐文章于 2023-11-11 09:00:00 发布