|
Gene,
Without actually writing the program, below is how I would
approach it:
bool Add3Values(BYTE val1, BYTE val2, BYTE val3, BYTE *Result,
BYTE *CarryResult)
{
// Add the 3 values together coming up with Result and
CarryResult
// If CarryResult overflows, return false, else return true
// CarryResult happens if adding x'FF' + x'FF' + x'FF'
}
AddStrings(BYTE *Str1, BYTE *Str2, BYTE *Result, int resLen)
{
// First, right adjust Str1 and Str2 making them the same
length.
// Next, make sure that resLen is at least 1 byte larger
then the largest
// of Str1 & Str2
BYTE CarryValue = 0;
For (int x = LargestLenOfStr1and2; x > 0; x--)
{
if (!Add3Values(Str1[x], Str2[x], &Result[x],
&CarryValue))
{
printf("Overflow has Overflowed! Croaking");
exit(-1);
}
}
// Now do something with Result.
}
Bob Crothers
> -----Original Message-----
> From: c400-l-bounces@xxxxxxxxxxxx
> [mailto:c400-l-bounces@xxxxxxxxxxxx] On Behalf Of
> Gene_Gaunt@xxxxxxxxxxxxxxx
> Sent: Thursday, November 13, 2003 4:31 PM
> To: C400-L@xxxxxxxxxxxx
> Subject: [C400-L] add long strings as unsigned integers
>
>
> How would you code addition of arbitrarily wide strings in C
language?
> For example
>
> x'88 00 00 00 88 00 00 00 00 22 00 00 00 33 00 00 E4'
> + x'88 00 00 00 F1 00 11 00 11 00 22 00 22 00 22 00 33'
> ------------------------------------------------------
> = x'10 00 00 01 79 00 11 00 11 22 22 00 22 33 22 01 17'
>
> _______________________________________________
> This is the C programming iSeries / AS400 (C400-L) mailing list
> To post a message email: C400-L@xxxxxxxxxxxx
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/c400-l
> or email: C400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/c400-l.
>
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.