PHP 计算两个特别大的整数实例代码
作者:IT钢铁小牛 时间:2024-05-11 10:07:33
废话不多说了,具体代码如下所示:
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 计算两个特别大的整数实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
来源:http://blog.51cto.com/13734105/2113228
标签:php,计算,整数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python仿抖音表白神器
2023-03-15 03:35:56
![](https://img.aspxhome.com/file/2023/4/107284_0s.jpg)
vue日期时间工具类详解
2024-06-07 16:06:22
![](https://img.aspxhome.com/file/2023/1/121961_0s.jpg)
Pandas DataFrame中的tuple元素遍历的实现
2023-12-21 09:47:00
ASP四级联动做法
2009-07-03 15:35:00
使用Python3+PyQT5+Pyserial 实现简单的串口工具方法
2021-09-09 16:49:42
![](https://img.aspxhome.com/file/2023/6/91896_0s.jpg)
从MySQL数据库表中取出随机数据的代码
2023-11-14 09:53:58
python 读取txt中每行数据,并且保存到excel中的实例
2022-06-14 02:28:09
python绘制BA无标度网络示例代码
2021-05-29 14:01:52
![](https://img.aspxhome.com/file/2023/7/70817_0s.jpg)
mysql5.7.17安装使用图文教程
2024-01-19 16:08:43
![](https://img.aspxhome.com/file/2023/5/119765_0s.png)
Python3.6中Twisted模块安装的问题与解决
2022-05-29 15:45:02
![](https://img.aspxhome.com/file/2023/0/75370_0s.png)
ORACLE 如何查询被锁定表及如何解锁释放session
2023-07-02 11:59:39
python 中collections的 deque使用详解
2023-02-07 15:43:14
关于python DataFrame的合并方法总结
2022-02-02 14:13:58
MySQL跨服务器关联查询的实现
2024-01-22 06:52:03
![](https://img.aspxhome.com/file/2023/9/106599_0s.jpg)
python实现批量视频分帧、保存视频帧
2023-07-04 19:59:18
Python实现批量压缩文件/文件夹zipfile的使用
2021-03-08 07:08:21
python实现单机五子棋
2021-04-26 05:34:35
![](https://img.aspxhome.com/file/2023/9/66459_0s.jpg)
golang三元表达式的使用方法
2023-08-28 14:34:09
![](https://img.aspxhome.com/file/2023/5/87625_0s.jpg)
sqlserver主键设计的注意点
2024-01-18 08:30:30
用FrontPage制作缩略图和图片重叠效果
2007-11-18 14:45:00