Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Python では、0b01001011 は 75 になり、これは 2 の補数でも機能します。しかし、0b10101001 は 169 になり、2 の補数では -87 になります。2 の補数バイナリ リテラルを表現するにはどうすればよいですか?
次のように、負のバイナリ リテラルを負の記号で表します。
>>> -0b1010111 -87
Python の整数は固定幅ではないため、「2 の補数」自体はありません。