PHP 计算两个特别大的整数实例代码
程序员文章站
2022-04-29 12:45:19
废话不多说了,具体代码如下所示:
function getintadd($a,$b){
$c = '';
$bcount = strlen($b);
$ac...
废话不多说了,具体代码如下所示:
function getintadd($a,$b){ $c = ''; $bcount = strlen($b); $acount = strlen($a); $count = max($bcount,$acount); $adiff = $count - $acount; $bdiff = $count - $bcount; for($i = $count - 1;$i >= 0;$i--){ $aval = $count - $i <= $acount ? intval($a[$i - $adiff]) : 0; $bval = $count - $i <= $bcount ? intval($b[$i - $bdiff]) : 0; $v = $aval + $bval; if(strlen($c) > 0 && strlen($c) >= $count - $i){ $c = ($v + intval($c[0])).substr($c,1,strlen($c) - 1); }else{ $c = $v.$c.''; } } return $c; } $a = '23490234328490289048902384908392849238'; $b = '234320498324982390489328498230984982399290384902384'; $c = getintadd($a,$b); print_r($c);
总结
以上所示是小编给大家介绍了php 计算两个特别大的整数实例代码,希望对大家有所帮助