Skip to content

Instantly share code, notes, and snippets.

@lucasdemarchi
Created June 21, 2018 23:52
Show Gist options
  • Save lucasdemarchi/84d1551698126b6c8314e12f18a98498 to your computer and use it in GitHub Desktop.
Save lucasdemarchi/84d1551698126b6c8314e12f18a98498 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
int i = atoi(argv[1]);
int idx;
for (idx = __builtin_ffs(i) - 1;
idx >= 0;
i ^= (1U << idx), idx = __builtin_ffs(i) - 1) {
printf("bit %d\n", idx);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment