📜  如何在python代码示例中将整数转换为十六进制符号2的补码

📅  最后修改于: 2022-03-11 14:45:54.450000             🧑  作者: Mango

代码示例1
def hex2complement(number):
    hexadecimal_result = format(number, "03X")
    return hexadecimal_result.zfill(4) # .zfill(n) adds leading 0's if the integer has less digits than n


# Examples:
# print(hex2complement(10)) outputs "000A"
# print(hex2complement(100)) outputs "0064"
# print(hex2complement(1000)) outputs "03E8"
# print(hex2complement(10000)) outputs "2710"
# print(hex2complement(100000)) outputs "186A0"