易截截图软件、单文件、免安装、纯绿色、仅160KB

我的C实践(9):位和字节的重排

  位和字节的重排在密码学算法中有广泛的应用。
/* rearran.c:位和字节的重排 */
/* 位反转:以字的中心为对称点进行位反射
例如: abcd efgh ijkl mnop ABCD EFGH IJKL MNOP
位反转:PONM LKJI HGFE DCBA ponm lkji hgfe dcba */
unsigned rev(unsigned x){
/* 交换相邻的单个位 */
x=(x & 0x55555555)<<1 | (x & 0xaaaaaaaa)>>1;
/* 交换相邻的2位字段 */
x=(x & 0x33333333)<<2 | (x & 0xcccccccc)>>2;
/* 交换相邻的4位字段 */
x=(x & 0x0f0f0f0f)<<4 | (x & 0xf0f0f0f0)>>4;
/* 交换相邻的8位字段 */
x=(x & 0x00ff00ff)<<8 | (x & 0xff00ff00)>>8;
/* 交换相邻的16位字段 */
x=(x & 0x0000ffff)<<16 | (x & 0xffff0000)>>16;
return x;
}
/* 字节反转:以字的中心为对称点进行字节反射
例如: abcd efgh ijkl mnop ABCD EFGH IJKL MNOP
字节反转:IJKL MNOP ABCD EFGH ijkl mnop abcd efgh */
unsigned revw(unsigned x){
x=(x & 0x00ff00ff)<<8 | (x & 0xff00ff00)>>8;
x=(x & 0x0000ffff)<<16 | (x & 0xffff0000)>>16;
return x;
}
/* 位混洗:将右半字的各个位相间地插入到左半字中,尾部的位仍然保留在尾部
例如:abcd efgh ijkl mnop ABCD EFGH IJKL MNOP
混洗:aAbB cCdD eEfF gGhH iIjJ kKlL mMnN oOpP */
unsigned shuffling(unsigned x){
unsigned t;
/* 初始:abcd efgh ijkl mnop ABCD EFGH IJKL MNOP */
/* abcd efgh ABCD EFGH ijkl mnop IJKL MNOP */
t=(x ^ (x>>8)) & 0x0000ff00; x=x ^ t ^ (t<<8);
/* abcd ABCD efgh EFGH ijkl IJKL mnop MNOP */
t=(x ^ (x>>4)) & 0x00f000f0; x=x ^ t ^ (t<<4);
/* abAB cdCD efEf ghGH ijIJ klKL mnMN opOP */
t=(x ^ (x>>2)) & 0x0c0c0c0c; x=x ^ t ^ (t<<2);
/* aAbB cCdD eEfF gGhH iIjJ kKlL mMnN oOpP */
t=(x ^ (x>>1)) & 0x22222222; x=x ^ t ^ (t<<1);
return x;
}
/* 逆混洗 */
unsigned unshuffling(unsigned x){
/* 以相反的顺序进行交换即可实现逆混洗 */
t=(x ^ (x>>1)) & 0x22222222; x=x ^ t ^ (t<&


相关文档:

no acceptable C compiler found in $PATH

GCC安装成功,所需文件有:
libf2c-3.3.2-1.i386.rpm
libstdc++-devel-3.3.2-1.i386.rpm
glibc-kernheaders-2.4-8.36.i386.rpm
glibc-headers-2.3.2-101.i386.rpm
glibc-devel-2.3.2-101.i386.rpm
gcc-objc-3.3.2-1.i386.rpm
binutils-2.14.90.0.6-3.i386.rpm
gcc-3.3.2-1.i386.rpm
gcc-c++-3.3.2-1.i386.rpm
autom ......

linux内核移植s3c2410,移植正式开始2

内核启动的现在已经是开始执行函数start_kernel函数了。start_kernel函数在init/main.c中定义。start_kernel函数只是完成
相应的结构的初始化任务。
    printk(KERN_NOTICE);
    printk(linux_banner);
    setup_arch(&command_line);
在uboot的一直过程中,uboo ......

keil C 从零学起 教训1

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num;
void main()
{
 TMOD=0x01;
 TH0=(65536-45872)/256;
 TL0=(65536-45872)%256;
 EA=1;
 ET0=1;
 TR0=1;
 P1=0xFF;
 while(1);
}
void T0_time() interrupt 1
{
  ......

我的C实践(8):字搜索

  字搜索就搜索一个数中具有某些特征的位。实现如下:
/* wsearch.c:字搜索 */
/* 从左边寻找第一个0字节:第0(1,2,3)个字节是0时,返回0(1,2,3),否则返回4 */
int zbytel(unsigned x){
if((x>>24)==0) return 0;
else if((x & 0x00ff0000)==0) return 1;
else if((x & 0x0000ff00)==0) r ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号