Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

23 digit number in numeric variable

Posted on 2006-04-25
15
Medium Priority
?
594 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:miltonrodrigueza
  • 6
  • 3
  • 2
  • +4
15 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 16535173

do the calculation on a string data
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 16535389
Int64 is insufficient for your needs as it ranges from
-9223372036854775808 .. 9223372036854775807

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

Regards
Pierre
0
 

Author Comment

by:miltonrodrigueza
ID: 16535473
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:miltonrodrigueza
ID: 16535489
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
 
LVL 28

Expert Comment

by:2266180
ID: 16535725
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
 
LVL 17

Expert Comment

by:mokule
ID: 16535785
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
 
LVL 1

Expert Comment

by:nou68
ID: 16535792
Search for representation of large integers in Pascal, you will find many implementaion
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 16535923
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
 
LVL 16

Expert Comment

by:CodedK
ID: 16536107
I was just about to post the above link :)
0
 
LVL 17

Expert Comment

by:mokule
ID: 16537156
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
 
LVL 17

Expert Comment

by:mokule
ID: 16537221
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
 
LVL 17

Accepted Solution

by:
mokule earned 1400 total points
ID: 16537321
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
 
LVL 28

Expert Comment

by:2266180
ID: 16537933
>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
 
LVL 17

Expert Comment

by:mokule
ID: 16538640
> 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
 
LVL 28

Expert Comment

by:2266180
ID: 16541829
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question