gpt4 book ai didi

python - 整数到字节的转换

转载 作者:太空宇宙 更新时间:2023-11-03 12:19:50 25 4
gpt4 key购买 nike

假设我有一个整数 13941412,我希望将其分成字节(该数字实际上是 0x00bbggrr 形式的颜色)。你会怎么做?在 c 中,您将数字转换为 BYTE,然后移动位。在 Python 中如何转换为 byte?

最佳答案

使用按位数学运算符,“字节”已经存在:

def int_to_rgb(n):
b = (n & 0xff0000) >> 16
g = (n & 0x00ff00) >> 8
r = (n & 0x0000ff)
return (r, g, b)

关于python - 整数到字节的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2562308/

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