Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <stdio.h>
static unsigned f(unsigned i) { return i * 40; }
static unsigned setbit(unsigned i, unsigned b) { return i | (1U << b); }
static unsigned clearbit(unsigned i, unsigned b) { return i & ~(1U << b); }
static void testbit(unsigned b) {
printf("bit %d : ", b);
unsigned i = 0;
do {
unsigned res = f(i);
if (f(setbit(i, b)) != res || f(clearbit(i, b)) != res) {
printf("demanded\n");
return;
}
i++;
} while (i != 0);
printf("not demanded\n");
}
int main(void) {
for (unsigned b = 31; b != -1; b--)
testbit(b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.