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

查看:40
本文介绍了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).

推荐答案

如果您使用架构可以处理的最大可能的本机表示(64 位)存储值(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 :) ).

但你总是可以使用更小的表示.4 个 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天全站免登陆