【问题标题】:python convert integer to bytes with bitwise operationspython通过按位运算将整数转换为字节
【发布时间】:2022-12-03 21:49:41
【问题描述】:

我有 2 个输入:i(整数)、长度(整数应编码多少字节)。

如何仅通过按位运算将整数转换为字节。

def int_to_bytes(i, length):
  for _ in range(length):
    pass

【问题讨论】:

    标签: python


    【解决方案1】:
    【解决方案2】:

    你可以只使用 bytes() 函数

    【讨论】:

    • 您将如何为此使用bytes()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    相关资源
    最近更新 更多