Operations with long numbers

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Operations with long numbers

Post 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. ;)
I get by with a little help from my friends
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Re: Operations with long numbers

Post by KDJ »

User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: Operations with long numbers

Post 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. :)
I get by with a little help from my friends
Post Reply