FAQ
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 golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Lgowkanapalli at Mar 28, 2013 at 8:49 pm
    Would the below algorithm work for when n = 21,000,000?


    From URL
    - http://computer-programming-forum.com/42-vhdl/7c45480b2bed31da.htm


    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[2] A[1] A[0] and is the current value.

    B is B[n-1] B[n-2] ... B[2] B[1] B[0] and is the next value.


    First, calaulate a parity bit P of A.

    P = A[0] XOR A[1] XOR A[2] ... XOR A[n-1].

    Then,

    B[0] = NOT A[0] XOR P
    B[1] = A[1] XOR (A[0] AND P)
    B[2] = A[2] XOR (A[1] AND NOT A[0] AND P)
    B[3] = A[3] XOR (A[2] AND NOT A[1] AND NOT A[0] 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[0]
    AND P)

    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[0] 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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Michael Poole at Mar 29, 2013 at 4:26 am

    On Thu, Mar 28, 2013 at 10:20 AM, 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.
    Use the standard method to construct a Gray code of length 2**N from
    http://aggregate.org/MAGIC/#Gray%20Code%20Conversion and skip either
    the first M and last M, or the middle 2*M, elements to yield your
    desired size. (Hat tip:
    http://www.eetimes.com/design/programmable-logic/4015117/How-to-generate-Gray-Codes-for-non-power-of-2-sequences
    .)

    --
    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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • David DENG at Mar 29, 2013 at 5:11 am
    http://play.golang.org/p/voT0OtfG4E

    An simple implementation.

    David
    On Thursday, March 28, 2013 10:20:09 PM UTC+8, 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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Paul Hankin at Mar 29, 2013 at 11:50 am

    On Thursday, 28 March 2013 15:20:09 UTC+1, 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.

    There's C code on http://en.wikipedia.org/wiki/Gray_code to convert to and
    from Gray codes. It translates easily into go.

    http://play.golang.org/p/7FS3Y8d28D

    --
    Paul Hankin

    --
    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 golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 28, '13 at 4:55p
activeMar 29, '13 at 11:50a
posts5
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase