Deriving nth Gray code from the (n-1)th Gray Code

前端 未结 2 1144
悲&欢浪女
悲&欢浪女 2021-01-07 13:32

Is there a way to derive the 4-bit nth Gray code using the (n-1)th Gray code by using bit operations on the (n-1)th Gray Code?

For example the 4th Gray code is 0010.

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 14:03

    What about the following?

    t1 := XOR(g0, g1)
    b0 := !XOR(g0, g1, g2, g3)
    b1 := t1 & g2 & g3 + !t1 & !g2 & !g3
    b2 := t1 & g2 & !g3
    b3 := t1 & !g2 & !g3
    
    n0 := XOR(b0, g0)
    n1 := XOR(b1, g1)
    n2 := XOR(b2, g2)
    n3 := XOR(b3, g3)
    

    The current gray code word is g3 g2 g1 g0 and the next code word is n3 n2 n1 n0. b3 b2 b1 b0 are the four bits which flip or not flip a bit in the code word to progress to the subsequent code word. Only one bit is changed between adjacent code words.

提交回复
热议问题