4
* Helper macros for large bit masks management
6
* Copyright (C) 2008 Jean-Philippe Meuret
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
/* Number of bits for 1 unsigned char */
24
#define nBitsPerUchar (sizeof(unsigned char) * 8)
26
/* Number of unsigned chars to contain a given number of bits */
27
#define nUcharsForNBits(nBits) ((((nBits)-1)/nBitsPerUchar)+1)
29
/* Index=Offset of given bit in 1 unsigned char */
30
#define bitOffsetInUchar(bit) ((bit)%nBitsPerUchar)
32
/* Index=Offset of the unsigned char associated to the bit
33
at the given index=offset */
34
#define ucharIndexForBit(bit) ((bit)/nBitsPerUchar)
36
/* Value of an unsigned char with bit set at given index=offset */
37
#define ucharValueForBit(bit) (((unsigned char)(1))<<bitOffsetInUchar(bit))
39
/* Test the bit with given index=offset in an unsigned char array */
40
#define testBit(bit, array) ((array[ucharIndexForBit(bit)] >> bitOffsetInUchar(bit)) & 1)