Gray to Binary Code
Here is one algorithm to convert from "natural binary codes" to Gray
code (encode):
Let B[n:0] the array of bits in the usual binary representation
Let G[n:0] the array of bits in gray code
G[n]=B[n]
for i=n-1 down to i=0 {
G[i]=B[i+1] XOR B[i]
}
Here is one algorithm to convert from Gray code to "natural binary codes" (decode):
B[n]=G[n]
for i=n-1 down to i=0 {
B[i]=B[i+1] XOR G[i]
}

0 Comments:
Post a Comment
<< Home