Format
#include <stdlib.h> /* also in <builtin.h> */ unsigned long _lrotl(unsigned long value, int shift); unsigned long _lrotr(unsigned long value, int shift);
Language Level: Extension
_lrotl and _lrotr rotate the unsigned long integer
value by shift bits. _lrotl rotates to the left, and _lrotr
to the right.
Note: Both _lrotl and _lrotr are built-in functions, which means they are implemented as inline instructions and have no backing code in the library. For this reason:
Return Value
Both functions return the rotated value.
There is no error return value.
Example
This example uses _lrotl and _lrotr
with different shift values to rotate the long integer value
0x01234567.
#include <stdio.h> #include <stdlib.h>
int main(void)
{
unsigned long val = 0X01234567;
printf("The value of 0x%8.8lx rotated 4 bits to the left is 0x%8.8lx\n", val,
_lrotl(val, 4));
printf("The value of 0x%8.8lx rotated 16 bits to the right is 0x%8.8lx\n",
val, _lrotr(val, 16));
return 0;
/****************************************************************************
The output should be:
The value of 0x01234567 rotated 4 bits to the left is 0x12345670
The value of 0x01234567 rotated 16 bits to the right is 0x45670123
****************************************************************************/
}
![]()
_crotl - _crotr -- Rotate
Bits of Character Value
_rotl - _rotr --
Rotate Bits of Unsigned Integer
_srotl - _srotr
-- Rotate Bits of Unsigned Short Value
<builtin.h>
<stdlib.h>