Subject: Re: max int value
To: Fong Siu Lung Gordon <ein@hkstar.com>
From: Jared D. McNeill <jmcneill@invisible.yi.org>
List: current-users
Date: 05/16/2000 07:16:21
On Tue, 16 May 2000, Fong Siu Lung Gordon wrote:
> Yes, 14-character. My method is to individually cut the 14-character into
> 14 tokens and calculate the check digit from these tokens. It works. The
> problem is I have to calculate the check digit for a series of borrow card
> not just one and I don't to type it again and again. The method I though
> of is to make a copy the start borrow card and increment by 1 each time.
> Then re-calculate the check digit and the new borrow card number. The
> probelm is max int of my system (i386) is largest enough to hold the
> 14-charater digit. That is the point.
If you're willing to do this in C++, you have a few options:
1. Use the BigInt class, it lets you work with huge numbers.
2. Use code in AddToBarCode() below
Alternately this code could probably be converted to C quite easily. Hope
this helps.
Jared
--
#include <iostream>
#include <string>
#include <cstdlib>
string AddToBarCode(string);
int
main()
{
string BarCode = "12345678901239";
cout << AddToBarCode(BarCode) << endl;
return(0);
}
string AddToBarCode(string BarCode)
// Variables: BarCode Initial barcode value
// Returns: New bar code as type string
{
int StringLen = 0;
int Flag = 0;
char WorkingChar;
string TempString = BarCode;
string TempChar;
StringLen = TempString.length();
WorkingChar = StringLen - 1;
while (!Flag)
{
TempChar = "";
TempChar += TempString[WorkingChar];
if (atoi(TempChar.c_str()) + 1 < 10)
{
TempString[WorkingChar] += 1;
Flag = 1;
} else {
TempString[WorkingChar] = '0';
WorkingChar--;
}
if (WorkingChar < 0)
{
TempString = "1" + TempString;
Flag = 1;
}
}
return(TempString);
}