Home  >  Article  >  Backend Development  >  将16进制转换成10进制整数

将16进制转换成10进制整数

WBOY
WBOYOriginal
2016-06-23 13:56:221604browse

双字节十六进制如何转换成十进制形式?
比如: 0xFFFFFFBF;
hexdec 函数转换会当4字节处理


回复讨论(解决方案)

$s = 0xFFFFFFBF;echo $s; //4294967231$s = 'FFFFFFBF';echo hexdec($s);//4294967231

不知道你想做什么?
你示例的是 4 字节数据

还是这个意思?
$n = 0xFFFFFFBF;$s = pack('L', $n);echo bin2hex($s), PHP_EOL;print_r(unpack('n*', $s));
bfffffff
Array
(
    [1] => 49151
    [2] => 65535
)

这个值转换出来应该是 -65,php弱类型会自动当作一个长整型处理,你看下windows计算器

$n = 0xFFFFFFBF;$s = pack('L', $n);print_r(unpack('l', $s));
Array
(
    [1] => -65
)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn