Last active
December 27, 2015 06:09
-
-
Save OlivierLi/7279447 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> | |
//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