search

Home  >  Q&A  >  body text

JAVA没有无符号整型,如何做无符号乘法和除法

虽然有无符号不影响加减法、位运算等操作,但是乘法和除法的指令分mul、p以及imul、ip两套的。

如果JAVA编程需要用到无符号乘除法怎么办?

天蓬老师天蓬老师2768 days ago625

reply all(3)I'll reply

  • PHPz

    PHPz2017-04-17 14:26:54

    If your source data is unsigned, that is, when it is less than Integer.MAX_VALUE and greater than or equal to 0, direct calculation is unsigned calculation. But if the data is actually larger than Integer.MAX_VALUE, you can use long to calculate it. If long is not enough, you can also use BigInteger.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 14:26:54

    It depends on the number of digits. If it is greater than int, use long. If long is not enough, use BigInteger, or simply use BigInteger directly

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 14:26:54

    Aren’t unsigned and signed operations the same in Java? Unsigned is nothing more than all positive numbers. What does the author want to express?

    reply
    0
  • Cancelreply