Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我编写了一个程序,仅使用字符串操作将二进制代码转换为格雷码。我想检查我的代码的可行性,以及它是正确还是错误的方法。
def binary_to_gray(x): x = str(x) gray = x[0] for i in range(len(x) - 1): if (x[i] == x[i + 1]): gray += "0" else : gray += "1"