Would the below algorithm work for when n = 21,000,000?
Here's the best algorithm I've come up with that works with any word
width. Assuming that the counter is n bits wide,
A is A[n-1] A[n-2] ... A A A and is the current value.
B is B[n-1] B[n-2] ... B B B and is the next value.
First, calaulate a parity bit P of A.
P = A XOR A XOR A ... XOR A[n-1].
B = NOT A XOR P
B = A XOR (A AND P)
B = A XOR (A AND NOT A AND P)
B = A XOR (A AND NOT A AND NOT A AND P)
The pattern that emerges is
B[k] = A[k] XOR (A[k-1] AND NOT A[k-2] AND NOT A[k-3] ... AND NOT A
except for k = n-1 where the A[k-1] term is left out so that
B[n-1] = A[n-1] XOR (NOT A[n-3] AND NOT A[n-4] ... AND NOT A AND P)
On Thursday, March 28, 2013 10:20:09 AM UTC-4, amslo...@gmail.com wrote:
Hi - Are there any gray code implementations or algorithms in GO that you
can point me to? I am looking for it work when n = 21,000,000.
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to email@example.com.
For more options, visit https://groups.google.com/groups/opt_out.