0

I want to get a binary code of integer in Python. I know about the bin() function. But firstly bin() is not retrieving, but converting. And secondly, it doesn't work with negative integers - I mean two's complement repr. As we know the computer saves negative integers in two's complement repr. So I want to retrieve that particular saved integer number as it is saved in memory. Is there any way solving?

  • For -1 I expect in 2's complement = 11. or in 32-bit repr it is 11111111111111111111111111111111. – Ruslan Mansurov May 18 '22 at 14:00
  • Technically you don't know that python stores integers internally in two's complement representation. python ints are arbitrary precision, and many arbitrary precision (aka "BigInteger") integer libraries stores the values internally in a sign-magnitude representation. – President James K. Polk May 19 '22 at 14:07

0 Answers0