1 /* Some elementary bit manipulations
10 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of
15 the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public
23 License along with this program; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32 /* number of bytes to hold n bits */
33 #define nbytes_for_bits(n) ((((n)-1)>>3)+1)
35 /* test if bit is set */
36 #define bit_is_set(b, var) ((var)[(b)>>3] & (1<<((b)&0x7)))
39 #define set_bit(b, var) ((var)[(b)>>3] |= (1<<((b)&0x7)))
42 #define clear_bit(b, var) ((var)[(b)>>3] &= ~(1<<((b)&0x7)))
45 #define clear_all_bits(b, var) memset(var, 0, nbytes_for_bits(b))
47 /* set range of bits */
48 #define set_bits(f, l, var) { \
50 for (i=f; i<=l; i++) \
54 /* clear range of bits */
55 #define clear_bits(f, l, var) { \
57 for (i=f; i<=l; i++) \
61 #endif /* __BITS_H_ */