This question has already been answered:

Explain please , you need to write functions for the bitwise addition and subtraction of long integers represented by strings of characters . If you can a couple of examples, I will be grateful.

Reported as a duplicate by participants aleksandr barakin , Grundy , Athari , Nick Volynkin Apr 22 '16 at 7:44 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • five
    Remember addition and subtraction in a column. That's the way it is done - Mike
  • The implementation of long arithmetic is in OpenSSL, look around BN_ * - Vladimir Martyanov
  • I would like to know the principle of what is meant, the more it is necessary to present it as a string, as I understood it - Zhenya

2 answers 2

for (int q=n; q--; ) if ((d = (res[i] = a[i] + b[i] - '0' + d) > '9' /* assignment */)) res[i] -= 10; 
  • Is this addition in the form of a string correct? - Zhenya
  • @ Eugene, yes, this is addition. - Qwertiy
  • @Qwertiy, well, at least else d = 0; imho worth adding. I would also draw the attention of the vehicle to the alignment of the "right edge". - avp
  • one
    @avp, corrected ... in some way :) - Qwertiy

A normal explanation of the basic principles of long arithmetic is here . These are the simplest implementations convenient for fast coding, but, truth, there are several digits stored in one int. Similarly, you can do one by one if it is more convenient. If necessary, I can provide links to professional literature on this topic.