#include <stdio.h> /* _lrotr() A function that shifts an unsigned long integer to the left Prototype :unsigned long
_lrotr(unsigned long value,int count) function : take value Cycle left count position .
Return value : take value Cycle left count Value after bit . Header file :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; }
// This function is called _rotl Function is encapsulated again unsigned long _lrotl (unsigned long val,int shift) {
return( (unsigned long) _rotl((unsigned) val, shift) ); } /*
_lrotr() A function that shifts an unsigned long integer to the right Prototype :unsigned long _lrotr(unsigned long value,int
count) function : take value Cycle right count position . Return value : take value Cycle right count Value after bit . Header file :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; } // Encapsulate the right shift function again 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
; } Operation results :32 2
Technology
Daily Recommendation