Task

Explicitly implement   long multiplication.

This is one possible approach to arbitrary-precision integer algebra.



For output, display the result of    264 * 264.

Optionally, verify your result against builtin arbitrary precision support.

The decimal representation of    264    is:

18,446,744,073,709,551,616

The output of    264 * 264    is    2128,    and is:

340,282,366,920,938,463,463,374,607,431,768,211,456



 
longmult := proc(a::integer,b::integer)
    local A,B,m,n,i,j;
    # Note, return a*b; works in Maple for any sized integer
    A := convert(a,base,10);
    B := convert(b,base,10);
    m := numelems(A);
    n := numelems(B);
    add( add( A[i]*B[j]*10^(j-1), j=1..n )*10^(i-1), i=1..m );
end;
 
> longmult( 2^64, 2^64 );
                    340282366920938463463374607431768211456
 