Skip to content

Instantly share code, notes, and snippets.

@regehr
Created January 22, 2020 03:50
Show Gist options
  • Save regehr/19b2ef7206922df5d455c1280dc7e8b7 to your computer and use it in GitHub Desktop.
Save regehr/19b2ef7206922df5d455c1280dc7e8b7 to your computer and use it in GitHub Desktop.
#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