Re: GrayCode
Gray->Decimal conversion consists of two steps:-
1) Gray -> Binary
2) Binary -> Decimal
FIRST convert a Gray-coded number to binary by follow this method :-
The binary number and the Gray-coded number will have the same number of bits
The binary MSB (left-hand bit) and Gray code MSB will always be the same
To get the binary next-to-MSB (i.e. next digit to the right) add the binary MSB and the gray code next-to-MSB.
Record the sum, ignoring any carry.
Continue in this manner right through to the end.
e.g.
Gray Code 10011011 Binary Digit 1 = 1 (same as Gray code)
Gray Code 10011011 Binary Digit 2 = 0 + 1 = 1
Gray Code 10011011 Binary Digit 3 = 0 + 1 = 1
Gray Code 10011011 Binary Digit 4 = 1 + 1 = 0 (carry 1)
Gray Code 10011011 Binary Digit 5 = 1 + 0 = 1
Gray Code 10011011 Binary Digit 6 = 0 + 1 = 1
Gray Code 10011011 Binary Digit 7 = 1 + 1 = 0 (carry 1)
Gray Code 10011011 Binary Digit 8 = 1 + 0 = 1
and so
10011011gray = 11101101bin
Now Convert this binary to Decimal using the method given below!!!
Let ans start at 0 and suppose
the binary number is 11010111. Then compute new values of ans as shown
below: ans * 2 + 1 =>ans
ans * 2 + 1 =>ans
ans * 2 + 0 =>ans
ans * 2 + 1 =>ans
ans * 2 + 0 =>ans
ans * 2 + 1 =>ans
ans * 2 + 1 =>ans
ans * 2 + 1 =>ans
At this point, ans contains the converted number.