Java: Implementing a Unsigned 128bit Integer

后端 未结 3 795
别跟我提以往
别跟我提以往 2021-02-13 19:13

first off I should ask:
Does anyone knows of a current implementation 128b UINT for Java?

I need something to hold natural cardinal

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 19:13

    Don't tell me that you plan to have 128 static setters and getters, one for each bit??? I'd definitively go for setBit(int index, boolean value) and getBit(int index) as instance methods.

    More things you need: a toString() method so you can get a human readable representation (at some point you will want to print the numbers, I think).

    Remember that all the ordinal types in java are signed (with the exception of char), so if you plan to use two longs, keep always in mind that the lower part could be problematic for detecting overflows and such... anyway, you will have a 127 bit number unless because the lower part would be treated as a 63 bit unsigned.

提交回复
热议问题