| Revision 1 (by moose, 2006/07/06 01:31:16) |
Initial import
|
#include <stdio.h>
#define BLOCK_SIZE 1024
// (BLOCK_SIZE << 5) == (BLOCK_SIZE * 32)
#define TOTAL_BITS (BLOCK_SIZE << 5)
// (BLOCK_SIZE >> 5) == (BLOCK_SIZE / 32)
#define TOTAL_BLOCKS (BLOCK_SIZE >> 5)
unsigned int bitmap[TOTAL_BLOCKS];
#define GET_BIT(v) ( (bitmap[v >> 10] >> (v % 32)) & 0x00000001 )
#define SET_BIT_ON(v) bitmap[v >> 10] |= (1 << (v % 32))
#define SET_BIT_OFF(v) bitmap[v >> 10] &= ~(1 << (v % 32))
int main()
{
int i = 0;
for(i = 0; i < TOTAL_BLOCKS; i++) {
bitmap[i] = 0xffffffff;
}
for(i = 0; i < TOTAL_BITS; i++) {
int idx = i >> 10;
int bit = (i % 32);
int val = (bitmap[idx] >> bit) & 0x00000001;
printf("%-04i bitmap[%i].%i: %i\n", i, idx, bit, val);
}
SET_BIT_OFF(3452);
printf("Bit 3452 == %i\n", GET_BIT(3452));
SET_BIT_ON(3452);
printf("Bit 3452 == %i\n", GET_BIT(3452));
SET_BIT_OFF(3452);
printf("Bit 3452 == %i\n", GET_BIT(3452));
SET_BIT_ON(3452);
printf("Bit 3452 == %i\n", GET_BIT(3452));
return 0;
}