1

I was wondering how python integers are implemented behind-the-scene, so that it is unbounded. If we consider implementation of integer data type of most other programming languages, 2's complement is used for those.

And 2's complement cannot be implemented with unlimited number of bits. But how python is doing that? Is it using some other technique rather than 2's complement? If yes, how addition and subtraction is done in python?

As far as I know, if we use 2's complement, a single circuit can be used to accomplish the operations of both addition and subtraction. Does python have two different circuits for these two operations?

azro
  • 53,056
  • 7
  • 34
  • 70
Ridwan Faiz
  • 85
  • 1
  • 6
  • That's implementation dependent, e.g. for CPython see https://stackoverflow.com/q/23016610/3001761 – jonrsharpe Dec 30 '22 at 16:15
  • Does this answer your question: https://www.codementor.io/@arpitbhayani/how-python-implements-super-long-integers-12icwon5vk – thebjorn Dec 30 '22 at 16:16

0 Answers0