【发布时间】:2021-12-28 06:32:55
【问题描述】:
谁能解释一下这段代码是如何工作的?我真的很感激
def inc_bytes(a):
""" Returns a new byte array with the value increment by 1 """
out = list(a)
for i in reversed(range(len(out))):
if out[i] == 0xff:
out[i] = 0
else:
out[i] += 1
break
return bytes(out)
【问题讨论】: