Debian Codegraph @

lib/util/bitarith.h

raw
1 #ifndef BITARITH_H_INCLUDED
2 #define BITARITH_H_INCLUDED
3
4 #include "pm_config.h"
5
6 static __inline__ unsigned char
7 pm_byteLeftBits(unsigned char const x,
8 unsigned int const n) {
9 /*----------------------------------------------------------------------------
10 Clear rightmost (8-n) bits, retain leftmost (=high) n bits.
11
12 Return arbitrary value if n > 8.
13 -----------------------------------------------------------------------------*/
14 unsigned char retval;
15
16 retval = x;
17 retval >>= (8-n);
18 retval <<= (8-n);
19
20 return retval;
21 }
22
23
24
25 static __inline__ unsigned char
26 pm_byteRightBits(unsigned char const x,
27 unsigned int const n){
28 /*----------------------------------------------------------------------------
29 Return rightmost (=low) n bits of x.
30
31 Return arbitrary value if n > 8.
32 -----------------------------------------------------------------------------*/
33 unsigned char retval;
34
35 retval = x;
36 retval <<= (8-n);
37 retval >>= (8-n);
38
39 return retval;
40 }
41
42 #endif