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?

2
  • For -1 I expect in 2's complement = 11. or in 32-bit repr it is 11111111111111111111111111111111. Commented May 18, 2022 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. Commented May 19, 2022 at 14:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.