如何确定 Python 中的补码和补码?

问题描述 投票:0回答:0

这是我目前所拥有的:

decimalEquivalent 是表示整数的变量。

#One's complement of the binary string is shown
onesComplement = bin(~decimalEquivalent)
print(f'The negative no (-{decimalEquivalent}) using 1\'s Complement: {onesComplement}')

#Two's complement of the binary string is shown
twosComplement = onesComplement + bin(1)
print(f'The negative no (-{decimalEquivalent}) using 2\'s Complement: {twosComplement}')

你能帮我弄清楚我做错了什么吗?

我试图确定整数的补码和补码。

python twos-complement ones-complement
© www.soinside.com 2019 - 2024. All rights reserved.