def tc_to_gray_code(x: int) ->int:
    """tc_to_gray_code(x) converts two's complement integer x to gray code
    integer. Raises ValueError if x < 0.
    """
    if x < 0:
        raise AssertionError('x must be non-negative')
    return x ^ x >> 1
