:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / stdlib / rot.c
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/crtdll/stdlib/rot.c
5  * PURPOSE:     Performs a bit wise rotation
6  * PROGRAMER:   Boudewijn Dekker
7  * UPDATE HISTORY:
8  *              03/04/99: Created
9  */
10
11 #include <crtdll/stdlib.h>
12
13 unsigned int _rotl( unsigned int value, int shift )
14 {
15         int max_bits = sizeof(unsigned int)<<3;
16         if ( shift < 0 )
17                 return _rotr(value,-shift);
18
19         if ( shift > max_bits )
20                 shift = shift % max_bits;
21         return (value << shift) | (value >> (max_bits-shift));
22 }
23
24 unsigned int _rotr( unsigned int value, int shift )
25 {
26         int max_bits = sizeof(unsigned int)<<3;
27         if ( shift < 0 )
28                 return _rotl(value,-shift);
29
30         if ( shift > max_bits<<3 )
31                 shift = shift % max_bits;
32         return (value >> shift) | (value <<  (max_bits-shift));
33 }
34
35
36 unsigned long _lrotl( unsigned long value, int shift )
37 {
38         int max_bits = sizeof(unsigned long)<<3;
39         if ( shift < 0 )
40                 return _lrotr(value,-shift);
41
42         if ( shift > max_bits )
43                 shift = shift % max_bits;
44         return (value << shift) | (value >> (max_bits-shift));
45 }
46
47 unsigned long _lrotr( unsigned long value, int shift )
48 {
49         int max_bits = sizeof(unsigned long)<<3;
50         if ( shift < 0 )
51                 return _lrotl(value,-shift);
52
53         if ( shift > max_bits )
54                 shift = shift % max_bits;
55         return (value >> shift) | (value << (max_bits-shift));
56 }