gpt4 book ai didi

python - 如何在 Python 中将整数视为字节数组?

转载 作者:太空狗 更新时间:2023-10-29 18:15:29 26 4
gpt4 key购买 nike

我正在尝试解码 Python os.wait() 函数的结果。根据 Python 文档,这将返回:

a tuple containing its pid and exit status indication: a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero); the high bit of the low byte is set if a core file was produced.

我如何解码退出状态指示(它是一个整数)以获得高字节和低字节?具体来说,如何实现以下代码片段中使用的解码功能:

(pid,status) = os.wait()
(exitstatus, signum) = decode(status)

最佳答案

这会做你想做的:

signum = status & 0xff
exitstatus = (status & 0xff00) >> 8

关于python - 如何在 Python 中将整数视为字节数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com