64位计算机上的无符号128位除法 [英] Unsigned 128-bit division on 64-bit machine

查看:242
本文介绍了64位计算机上的无符号128位除法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个128位数字存储为2个64位数字( Hi和 Lo)。我只需要将其除以32位数字即可。我该怎么做,使用CPU的本机64位操作?

I have a 128-bit number stored as 2 64-bit numbers ("Hi" and "Lo"). I need only to divide it by a 32-bit number. How could I do it, using the native 64-bit operations from CPU?

(请注意,我不需要任意精度库。只需要知道如何

(Please, note that I DO NOT need an arbitrary precision library. Just need to know how to make this simple division using native operations. Thank you).

推荐答案

如果您使用以下方式存储值(128位),

If you are storing the value (128-bits) using the largest possible native representation your architecture can handle (64-bits) you will have problems handling the intermediate results of the division (as you already found :) ).

但是,您的体系结构可以处理的最大本机表示形式(64位)在处理除法的中间结果时会遇到问题。您总是可以使用SMALLER表示形式。那四位数的32位呢?这样,您可以使用本机64位操作而不会出现溢出问题。

But you always can use a SMALLER representation. What about FOUR numbers of 32-bits? This way you could use the native 64-bits operations without overflow problems.

一个简单的实现(在Delphi中)可以在此处

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

这篇关于64位计算机上的无符号128位除法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆