Java 将两个 BigInt 对象相乘
有一个 BigInt 类和两个对象 num1 和 num2。我有一个实验室作业,我必须将 num1 和 num2 相乘。它们可以是最多 50 位的整数。该类有一个大小和一个数字。大小是输入的整数中的位数,数字是保存该整数的数组。
我必须编写一个方法来将这两个对象相乘并返回乘积。我对如何开始这个有点困惑。我见过有两个环和一个底座的例子。我不知道这个基地会用来做什么。
任何正确方向的指示将不胜感激。
Theres a BigInt class and two objects num1 and num2. I have a lab assignment and i have to multiply num1 and num2. they can be an integer up to 50 digits. the class has a size and a digit.size is the number of digits in the integer that is entered and digit is an array that holds the integer.
I have to write a method that multiplies these two objects and returns the product. Im a little confused on how to start this. Ive seen examples where there are two loops and a base. I have no idea what the base would be used for.
any pointers in the right direction would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设基数是十进制/十六进制等,为了更通用的实现......
通常,您需要使用正常的长乘法,就像在学校学到的那样。
另请注意,结果的长度可能长达 100 位 - 如果您只需要 50 位最低有效位,则可以稍微优化长乘法(几乎将其减半)。
I assume base is decimal / hexadecimal etc., for a more general implementation...
Generally, you need to use normal long multiplication, like learned in school.
Also note that the result could be up to 100 digits in length - if you just need the 50 least significant, you could optimize the long multiplication a bit (pretty much cut it in half).