int bitValue(bitSet bs, int index){ bitSet temp = bs; bitSet compare = makeBitSet(); setBit(&compare, index); temp = temp & compare; temp >>= index; return (int) temp; }
int main() { bitSet set = makeBitSet(); displayBitSet(set); setBit(&set, 4); printf("setting the bit at index 4 to 1...\n"); displayBitSet(set); clearBit(&set, 4); printf("setting the bit at index 4 to 0...\n"); displayBitSet(set); printf("getting the value of the bit at index 4...\n"); printf("%d\n", bitValue(set, 4)); }
int main(){ int x; bitSet bs = makeBitSet(); printf("display test \n"); displayBitSet(bs); printf("set test \n"); setBit(&bs, 3); displayBitSet(bs); setBit(&bs, 5); displayBitSet(bs); printf("value test \n"); x = bitValue(bs, 3); printf("bit value: %d \n", x); x = bitValue(bs, 2); printf("bit value: %d \n", x); printf("bit clear test \n"); clearBit(&bs, 3); displayBitSet(bs); }
void clearBit(bitSet* bs, int index){ bitSet temp = makeBitSet(); setBit(&temp, index); temp = ~temp; *bs = *bs & temp; }