in reply to String adding

You may want to look at using something like bignum with one of the approaches below above. With numbers this large, I believe Perl will convert them into floating-point numbers, and so will lose accuracy.

The alternative is to handle the carry-out parts yourself, but that's hard, and is essentially what bignum does anyways.

Update: Oops, I misread the question; I thought you were adding two strings of hex digits, not adding up the hex pairs in one string. Thanks to ikegami and Roy Johnson for showing me the error of my ways. :)

Replies are listed 'Best First'.
Re^2: String adding
by ikegami (Patriarch) on Nov 11, 2005 at 19:38 UTC

    bignum isn't needed. The example only requires 11 bits, for example.

    Perl uses doubles which have 52 bits of precision. The above algorithms can safely handle strings
    (((2^52)-1)/((2^8)-1))*2 = 17,661,175,009,296 chararacters long.

    Using just ints on a 32 bit system, the above algorithms can safely handle strings
    (((2^32)-1)/((2^8)-1))*2 = 16,843,008 chararacters long.