_rotl, _rotr

Rotate bits to the left (_rotl) or right (_rotr).

unsignedint_rotl(unsignedintvalue**,intshift);**

unsignedint_rotr(unsignedintvalue**,intshift);**

Routine Required Header Compatibility
_rotl <stdlib.h> Win 95, Win NT
_rotr <stdlib.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Both functions return the rotated value. There is no error return.

Parameters

value

Value to be rotated

shift

Number of bits to shift

Remarks

The _rotl and _rotr functions rotate the unsigned value by shift bits. _rotl rotates the value left. _rotr rotates the value right. Both functions “wrap” bits rotated off one end of value to the other end.

Example

/* ROT.C: This program uses _rotr and _rotl with
 * different shift values to rotate an integer.
 */

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
   unsigned val = 0x0fd93;
   printf( "0x%4.4x rotated left three times is 0x%4.4x\n",
           val, _rotl( val, 3 ) );
   printf( "0x%4.4x rotated right four times is 0x%4.4x\n",
           val, _rotr( val, 4 ) );
}

Output

0xfd93 rotated left three times is 0x7ec98
0xfd93 rotated right four times is 0x30000fd9

Floating-Point Support Routines

See Also   _lrotl