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