Home » Technical Questions » Programming

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

Correct Answer: 1 char arr[NUMSLOTS(50)]; 2 SET (arr, 20); 3 if (TEST (arr, 40))

← Previous Question Next Question→

More Questions from Programming

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion