Well the idea of bit fiddling or twiddling is pretty well established and there's a good deal of stuff out there on the web if you want to look it up.
A similar (in spirit) activity can be done with the plain everyday number sequence 0,1,2,3 etc. and I wanted to know (if I describe it properly) what other people here might call it so I can google it and see if there are any recipes out there. By the way no branching (if's or ternary's) allowed.
will get you 0,0,0,0,1,1,1,1,0,0,0,0 , a square wave alternatiing between 0 and 1 every 4 steps.Code:int N=16; for(i=0;i<N;i++) printf("%i ",(i/4)%2);
I've been trying to get 0,1,1,1,0,-1,-1,-1,0,1 etc and have got
but of course I need to get the zero coming up every power of 4 times. I'm sure this has been hacked out a number of times but don't quite know how to look it up.Code:int N=16; for(i=0;i<N;i++) printf("%i ",1-2*(i/4)%2);
Suggestions welcome thank you for reading.