#include <stdio.h> /* _lrotr()将一个无符号长整形数左循环移位的函数 原形:unsigned long
_lrotr(unsigned long value,int count) 功能:将value向左循环移动count位。
返回值:将value向左循环移动count位后的值。 头文件:stdlib.h */ unsigned _rotl (unsigned val,int
shift) { register unsigned hibit; /* non-zero means hi bit set */ register
unsigned num = val; /* number to rotate */ shift &= 0x1f; /* modulo 32 -- this
will also make negative shifts work */ while (shift--) { hibit = num &
0x80000000; /* get high bit */ num <<= 1; /* shift left one bit */ if (hibit)
num |= 1; /* set lo bit if hi bit was set */ } return num; }
//这个函数就是将_rotl函数做再次封装 unsigned long _lrotl (unsigned long val,int shift) {
return( (unsigned long) _rotl((unsigned) val, shift) ); } /*
_lrotr()将一个无符号长整形数右循环移位的函数 原形:unsigned long _lrotr(unsigned long value,int
count) 功能:将value向右循环移动count位。 返回值:将value向右循环移动count位后的值。 头文件:stdlib.h */
unsigned _rotr (unsigned val,int shift) { register unsigned lobit; /* non-zero
means lo bit set */ register unsigned num = val; /* number to rotate */ shift
&= 0x1f; /* modulo 32 -- this will also make negative shifts work */ while
(shift--) { lobit = num & 1; /* get high bit */ num >>= 1; /* shift right one
bit */ if (lobit) num |= 0x80000000; /* set hi bit if lo bit was set */ }
return num; } //对右移函数做再次封装 unsigned long _lrotr (unsigned long val,int shift) {
return( (unsigned long) _rotr((unsigned) val, shift) ); } int main(void) {
unsigned long val = 2; unsigned long ret = _lrotl(val , 4) ;
printf("%d\n",ret); unsigned long r = _lrotr(ret,4); printf("%d\n",r); return 0
; }运行结果:32 2

技术
今日推荐
阅读数 12
阅读数 11
阅读数 10
©2020 ioDraw All rights reserved
【C语言】乘法表韦恩图解决数学问题10个Python爬虫入门实例Java版斗地主代码免费复制FDTD solution——材料拟合、光源设置时间类型转换的问题“2021-01-20T10:09:11Z”python gui界面实例-Python GUI编程完整示例漫谈TCP加速的笑话用python的turtle库绘制风车动画❀Linux系统上C语言的编译与调试你还不知道吗?❀