Java:实现无符号128位整数 [英] Java: Implementing a Unsigned 128bit Integer
问题描述
首先我应该问:
有没有人知道当前的实现128b UINT for Java?
我需要一些东西来保持自然的基数值。即:一个巨大的计数器。
我知道BigIntegers,它是缓慢且不可变的。一个128b UINT是有意义的......
I need something to hold natural cardinal values. ie: A huge counter.
I know of BigIntegers, which are slow and immutable. A 128b UINT makes sense ...
我正在考虑使用一对原始long来实现一个OWORD。
I was thinking about implementing an OWORD, using a pair of primitive longs.
溢出会引发异常,而不是Wraparound。
Overflows would throw an Exception and not Wraparound.
我应该使用哪些示例源代码/博客来实现此类的工作方式?
推荐答案
我会使用32位整数作为表示,因为你需要一个更大的类型(长)来获得额外的精度用于进位,溢出检测和乘法。将32位整数视为数字并应用小学的算法。
I would use 32 bit integers as the representation, because you need a bigger type (long) to get the extra precision for the carry bit, overflow detection and multiplication. Think of a 32 bit integer as a digit and apply the algorithms from primary school.
这篇关于Java:实现无符号128位整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!