13 years ago

64-bit arithmetic on 32-bit machine?

How to implement 64-bit multiplication and division on 32-bit machine?
Top 1 Answers
13 years ago
Favorite Answer
The answer depends on the details of the 32-bit machine, but the most obvious solution for multiplication is to treat each number as if it were split into two 32-bit parts. If each symbol below represents a 32-bit part:  AB  CD ----   E  F  G H where: E = B*D F = A*D * 2^32 G = B*C * 2^32 H = A*C * 2^64 This is like performing multiplication "by hand", except that each digit is base 2^32 rather than base 10. Note that this requires 64-bit addition (which can easily be simulated on a 32-bit machine) as well as a "carry bit" to keep track single-bit overflow from the 32x32 multiplies. Also note that the multiplication by 2^32 and 2^64 can be implemented by offsetting the value within the result (ie. a virtual "shift" operation). There appears to be an implementation for x86 at: http://www.gidforums.com/t-18005.html .