Created
January 22, 2020 03:50
-
-
Save regehr/19b2ef7206922df5d455c1280dc7e8b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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