Q:
Answer the following Program
#define CHARSIZE 8
#define MASK(y) (1 << y % CHARSIZE)
#define BITSLOT (y) (y / CHARSIZE)
#define SET(x,y) ( x[BITSLOT(y)] = MASK(y) )
#define TEST(x,y) ( x[BITSLOT(y)] & MASK(y) )
#define NUMSLOTS(n) ((n + CHARSIZE - 1) / CHARSIZE)
Give the above macros how would you
1. declare an array arr of 50 bits
2. put the 20th bit on
3. test whether the 40th bit is on or off
Answer
1. char arr[NUMSLOTS(50)];
2. SET (arr, 20);
3. if (TEST (arr, 40))
View answer
Workspace
Report Error
Discuss