拆分 BigInteger,计算数字?
您是否有可能想到一种有效的方法将 BigInteger 分成两半,即如果数字是 12345678,它将被分成 1234?我想我可以将其更改为字符串并使用子字符串,但我不确定这是否是最快的方法。
您还知道如何计算 BigInteger 中的位数吗?我知道您可以执行 bitLength 和 bitCount,但我认为它们是二进制补码。我正在尝试跟踪我将它们分开的位置?
Any chance you might be able to think of an efficient way to split a BigInteger in half, i.e. if the number is 12345678, it would be split into 1234? I was thinking that I could change it into a string and use substring, but I'm not sure if that would be the fastest way to do it.
Do you also know how to count the number of digits in BigInteger? I know that you can do a bitLength and bitCount, but I think those are in two's complements. I'm trying to keep track of where I split them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有人问如何计算二进制数中的十进制位数:https://math.stackexchange.com/questions/3987/how-to-calculate-the-number-of-decimal-digits-for-a-binary-number
看起来这件事并不小。因此,您很可能必须转换为字符串并从那里开始工作。
Some asked how to calculate the number of decimal digits in a binary number here: https://math.stackexchange.com/questions/3987/how-to-calculate-the-number-of-decimal-digits-for-a-binary-number
Seems like its not trivial. So it is very likely that you will have to convert to a String and work from there.
转换为字符串可能是您最好的选择,因为听起来您正在寻找“文本”半点和长度,而这不是“数字”表示提供的。
Converting to String is probably your best bet because it sounds like you're looking for the 'textual' half point and length, which is not something that 'numerical' representations provide.