[prev] 41 [next]

Exercise 5: Implement Bit operations

Given the following definitions:

#define NBITS 1024
#define NWORDS (NBITS/32)
typedef unsigned int Word;
typedef Word BitS[NWORDS];

Implement functions for

  • getBit(Bits b, int i) ... get value of i'th bit, 0 or 1
  • setBit(Bits b, int i) ... ensure i'th bit is set to 1
  • unsetBit(Bits b, int i) ... ensure i'th bit is set to 0