Skip to content

Instantly share code, notes, and snippets.

@OlivierLi
Last active December 27, 2015 06:09
Show Gist options
  • Save OlivierLi/7279447 to your computer and use it in GitHub Desktop.
Save OlivierLi/7279447 to your computer and use it in GitHub Desktop.
#include <stdio.h>
//This is a simple program that counts from 0 to 63 in a loop without conditional statements or use of modulo
int main(void) {
int i=0;
int cntr=0;
// 0x3f = 0011 1111
// 64 = 0100 0000
// Whatever is on the right of bit #7 is kept.
// When bit #7 is set and the rest is not (i is divisible by 64) no bits are equal and so the result is 0
while(1) {
cntr = (++i & 0x3f);
printf("%d\n",cntr);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment