Unsigned 128-bit division on a 64-bit machine

I have a 128-bit number stored as 2 64-bit numbers ("Hello" and "Lo"). I only need to divide it into a 32 bit number. How can I do this using my own 64-bit processor operations?

(Please note that I DO NOT need a library with arbitrary precision. You just need to know how to make this simple separation using your own operations. Thank you).

+5
integer-division
Dec 08 '09 at 22:02
source share
2 answers

If you save the value (128 bits) using the maximum possible native representation that your architecture can process (64-bit), you will have problems processing the intermediate division results (as you already found :)).

But you can always use the SMALLER view. How about FOUR 32-bit numbers? Thus, you can use your own 64-bit operations without overflow problems.

A simple implementation (in Delphi) can be found here .

+3
Dec 09 '09 at 23:38
source share

Some c codes are here .

+2
Dec 08 '09 at 23:56
source share



All Articles