Skip to content

Instantly share code, notes, and snippets.

@miura1729
Created August 21, 2026 10:29
Show Gist options
  • Select an option

  • Save miura1729/bb57c69a6bbf71448887bab5f8e2bef8 to your computer and use it in GitHub Desktop.

Select an option

Save miura1729/bb57c69a6bbf71448887bab5f8e2bef8 to your computer and use it in GitHub Desktop.
div 7
#include <stdio.h>
int div7(int n)
{
int res = 0;
int cnt = 0;
while (n > 0) {
int nn = (8 - (n & 7));
res = res + (nn << cnt);
n -= ((nn << 3) - nn);
n >>= 3;
cnt += 3;
}
return res;
}
main(){
for(int i = 0; i < 1000; i++) {
printf("%d %d \n", i, div7(i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment