_rotl, _rotr

Description

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

#include <stdlib.h>

unsigned int _rotl( unsigned int value, int shift );

unsigned int _rotr( unsigned int value, int shift );

value Value to be rotated  
shift Number of bits to shift  

Remarks

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

Return Value

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

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

_lrotl, _lrotr

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 0xec9f

0xfd93 rotated right four times is 0x3fd9