23 digit number in numeric variable

Hi,

I need to store a 23 digit number in a 'numeric' variable. e.g. 20041010050500013402606
At the moment i have the string stored in a 'String' variable, However i need to convert it to a numeric type variable in order to apply a modulus 97.
I have tried with an integer variable using StrToInt(), I have tried with an Int64 variable using StrToInt64() but unfortunately it always come back with a compilation error "Integer constant too long". If i continue the execution of the program the the system throws an error message that reads "20041010050500013402606 is not a valid integer value"
I am currently using Delphi 6 enterprise edition.

I appreciate any help you can provide me with on this matter.

Cheers.
miltonrodriguezaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mokuleCommented:

do the calculation on a string data
0
Pierre CorneliusCommented:
Int64 is insufficient for your needs as it ranges from
-9223372036854775808 .. 9223372036854775807

i.e. max of 19 digits, you need 23

Regards
Pierre
0
miltonrodriguezaAuthor Commented:
Hi Mokule,

I need to apply a Modulus 97 to that value and as far as i understand the function MOD requires 2 integer input parameters so i do not know how to do that calculation with a string parameter, could you please instruct me how to do that?


Many thanks.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

miltonrodriguezaAuthor Commented:
Hi PierreC,

Thanks for the info. Do you have any ideas how can i work around this issue... maybe a user defined type or something like that.

Regards,
0
2266180Commented:
for a string library on big integers, see my post with the code from here: http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21812621.html
0
mokuleCommented:
get the two highest order digits convert to integer.
if it is greater or equal 97 subtract 97 from it
The difference multiply by 10 add next digit and continue.
0
nou68Commented:
Search for representation of large integers in Pascal, you will find many implementaion
0
DavidBirch2dotComCommented:
Hi, I think this is what you are looking for

http://delphiforfun.org/Programs/Library/big_integers.htm

Operations supported are: Assign,  Add, Subtract, Multiply, Divide, Modulo, Compare, Factorial, and ConvertToDecimalString.  

It will support integers far larger than your needs

David

0
CodedKCommented:
I was just about to post the above link :)
0
mokuleCommented:
By no means it's efficient.
But is it worth to install those libraries for a few lines of code?

function Modulo97(s: string): integer;
var
  val: integer;
  i: integer;
begin
  val := 0;
  if Length(s) > 0 then
    begin
    val := Ord(s[1])-Ord('0');
    i := 2;
    while i <= Length(s) do
      begin
      val := 10*val+Ord(s[i])-Ord('0');
      val := val mod 97;
      Inc(i);
      end;
    end;
  Result := val;
end;
0
mokuleCommented:
A little bit simpler version.
I've assumed it's positive and I don't check for valid chars.

function Modulo97(s: string): integer;
var
  val: integer;
  i: integer;
begin
  val := 0;
  if Length(s) > 0 then
    begin
    i := 1;
    while i <= Length(s) do
      begin
      val := 10*val+Ord(s[i])-Ord('0');
      val := val mod 97;
      Inc(i);
      end;
    end;
  Result := val;
end;
0
mokuleCommented:
ok. my final version

function Modulo97(s: string): integer;
var
  val: integer;
  i: integer;
begin
  val := 0;
  for i := 1 to Length(s) do
    begin
    val := 10*val+Ord(s[i])-Ord('0');
    val := val mod 97;
    end;
  Result := val;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
2266180Commented:
>But is it worth to install those libraries for a few lines of code?

there is nothing to install for my code, for example (I didn't look at the others) It's just a copy paste in a unit and that's that :)
0
mokuleCommented:
> ciuly
sorry to be awkward :(
I appreciate a lot of work, but Your solution makes no real sens.
It's so slow You can't calculate modulo on 9 digit numbers. not speaking of 23.
0
2266180Commented:
hm... you have a point here :) I actually designed it for big numbers (a AND b being big numbers) in which case it works pretty good.
well, my bad. never mind my code, it's not for this particular issue :D
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.