def rev_grey_code(g):
    """ 
    Decode grey code :
        Enter a number @g, return the vaule before encode to grey code. 
    """
    n = 0
    while g:
        n ^= g
        g >>= 1
    return n