Page 1 of 1

Operations with long numbers

Posted: Fri Nov 24, 2017 4:18 pm
by BeGeS
Hi all.

This morning I had the need to know the control code to obtain the IBAN (International Bank Account Number) of a series of accounts.

The formula is very simple: to the 20 digits of the old CCC, the 6 digits of the country are added; then it is divided by 97, and the remainder is taken; finally, the control code = 98 - remainder.

The problem comes when trying to divide a number of 26 digits, because for such operation Harbour admits up to 18 (even rounds the amount to those 18 digits).

I have been able to solve it by creating a function that I have called "ABACUS" (a laugh) and that consists of performing the operations by breaking the 26 digits in two blocks of 13:

Code: Select all

FUNCTION ABACUS()
LOCAL V1,V2,R1,R2,R3

  CCC:="11112222333344445555142800"  // PUBLIC VARIABLE OF
                                     // THE ACCOUNT CODE

  V1:=VAL( LEFT(CCC,13) )
  V2:=VAL( RIGHT(CCC,13) )
  
  R1:=V1%97            // REMAINDER OF THE FIRST HALF OF CCC

  R2:=R1*(10**13)+V2   // MULTIPLY THE FIRST REMAINDER BY 10^13
                       // AND ADDED TO THE SECOND HALF OF CCC
  
  R3:=R2%97            // REMAINDER OF CCC/97

RETURN R3

The question is: do you know any way to perform the division operation in a simpler way, without having to resort to "old dog" tricks?

Thanks. ;)

Re: Operations with long numbers

Posted: Fri Nov 24, 2017 7:20 pm
by KDJ

Re: Operations with long numbers

Posted: Sat Nov 25, 2017 9:17 am
by BeGeS
KDJ wrote: Fri Nov 24, 2017 7:20 pm BeGeS

Maybe this will be useful: https://en.wikipedia.org/wiki/Internati ... g_the_IBAN
:lol: :lol: :lol:

Thanks, KDJ. ;)
But the system proposed is the same as mine; the only difference is that I do it in two steps and he in four. I take half.
The good thing is that now I know that what I did, I did well. :)