#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

技术
©2020 ioDraw All rights reserved
OpenCV之IplImage详解央行:微信支付宝和数字人民币不存在竞争关系vue el-input 禁止输入特殊字符 只可输入数字 正则验证今天你抱怨了吗?分享一场黑客帝国代码雨脚本,简单好玩!详解PHP中的die、exit、return天猫等网店要挟用户成风?要硬钢!别惯他们臭毛病使用函数实现两个数的交换(C语言)django不关闭CSRF中间件,自定义通过CSRF检测的post请求python网络编程简单记录