PHP 大整数处理,10进制转16进制,16进制转10进制

2020-06-07 15:20:26  [ php ]      留言:0      阅读:13

来源:https://www.oschina.net/question/1781501_2270125


<php


require(__DIR__.'/../Math/BigInteger.php');


$f = 30 * pow(10, 9);
$g = new Math_BigInteger($f, 10);      //得到正确的16进制: 06fc23ac00
$h = dechex($f);                               //得到错误的16进制:     fc23ac00      ,丢失了两位


总之,只要10进制大于4 后面9个0,在10进制转16进制的时候,就不正确,丢失前面的位数。


---------------------------------


tcxu

2017/11/23 10:12

打开:下载 pear 的 BigInteger.php 的网址

Download For manual installation only 1.0.3 (这里,单击 1.0.3 就行)

成功之后,经过解压,即可在文件夹 Math_BigInteger-1.0\Math_BigInteger-1.0.3\Math

内找到BigInteger.php文档

<html> <head> <meta charset="utf-8" /> <title> </title> </head> <body> <?php require('Math/BigInteger.php');
$hex = "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7";
$b = new Math_BigInteger($hex,16); echo hexdec($hex).'<br>'; echo $b; ?> </body> </html>




来源:https://www.oschina.net/question/1781501_2270125


留言:


    更换校验码     

无觅相关文章插件,快速提升流量
分享到:
友荐云推荐 Process: 0.0325s ( Load:0.0003s Init:0.0008s Exec:0.0195s Template:0.0121s ) | DB :14 queries 1 writes | UseMem:3,018 kb