位逆置变换
来源:互联网 发布:歼十外销知乎 编辑:程序博客网 时间:2024/06/06 15:41
将数组
int a[] = {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7};
进行位逆置变换变为
{0 , 4 , 2 , 6 , 1 , 5 , 3 , 7};
变换前二进制表示为:
000 , 001 , 010 , 011 , 100 , 101 , 110 , 111
变换后:
000 , 100 , 010 , 110 , 001 , 101 , 011 , 111
代码如下:
#include <iostream>using namespace std;// the array size must be is 2 of pow// such as : 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7// binary express is :000 , 001 , 010 , 011 , 100 , 101 , 110 , 111// the reserve bit is : 000 , 100 , 010 , 110 , 001 , 101 , 011 , 111// 0 , 4 , 2 , 6 , 1 , 5 , 3 , 7template<size_t N>void ReserveBit( int( &n )[N] ){ int size = log( N ) / log( 2 ); for( int index = 0; index < N; index++ ) { int answer = 0; int bit = 1; for( int i = 0; i < size; i++ ) { answer <<= 1; if( n[index] & bit ) { answer |= 1; } bit <<= 1; } n[index] = answer; }}int main( void ){ int a[] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 }; ReserveBit( a ); int size = sizeof( a ) / sizeof( a[0] ); for( int i = 0; i < size; i++ ) { cout << i << ": " << a[i] << endl; } system( "pause" ); return 0;}
结果如下:
0 0
- 位逆置变换
- 变换
- 变换
- Hough变换
- Hough变换
- 变换读取
- 几何变换
- 坐标变换
- 变换img
- 傅立叶变换
- 傅立叶变换
- 行列变换
- 傅立叶变换
- 图形变换
- Gabor变换
- 视图变换
- 模型变换
- 坐标变换
- Ie中的404错误
- Redis源码阅读之aof.c
- 【c语言】关于+1的各种情况
- HDU4706——Children's Day(简单模拟)
- 细说UI线程和Windows消息队列
- 位逆置变换
- 获取字符串中每个字母出现的次数
- Implement Trie (Prefix Tree)
- 二分查找法--while语句实现
- KMP
- linux下安装flashplayer
- 响应式布局的三大要点
- 用两个栈实现队列
- 解决支持arm64的 lame库