Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php将十六进制转换为十进制无效_Php_Hex_Decimal_Type Conversion - Fatal编程技术网

php将十六进制转换为十进制无效

php将十六进制转换为十进制无效,php,hex,decimal,type-conversion,Php,Hex,Decimal,Type Conversion,我正在尝试将0d0c140d2f3b的十六进制值转换为十进制。hexdec()和base_convert()的值为14345527177019 该值应为13 12 20 13 47 59 private function convert_rtc($hex_rtc) { $rtc = hexdec($hex_rtc); return $rtc; 如果我应该使用不同的函数,请告诉我。谢谢将0d0c140d2f3b的原始值拆分为两个字符的块(例如0d0c140d

我正在尝试将0d0c140d2f3b的十六进制值转换为十进制。hexdec()和base_convert()的值为14345527177019

该值应为13 12 20 13 47 59

   private function convert_rtc($hex_rtc) {
        $rtc = hexdec($hex_rtc);
        return $rtc;

如果我应该使用不同的函数,请告诉我。谢谢

0d0c140d2f3b
的原始值拆分为两个字符的块(例如
0d
0c
14
0d
2f
3b
),然后在每个块上使用hexdec()

PHP的函数在这里应该很有用

编辑

比如说

function convert_rtc($hex_rtc) {
    $rtc = array_map(
        'hexdec',
        str_split($hex_rtc, 2)
    );
    return $rtc;
}

$hexString = '0d0c140d2f3b';

$result = convert_rtc($hexString);
var_dump($result);
试试这个。。

它为您提供了正确的值。显然,您希望将每2个十六进制数字转换为一个单独的数字,而不是转换整个数字,这是一个完全不同的问题。
Try this..

<?php
var_dump(hexdec("See"));
var_dump(hexdec("ee"));
// both print "int(238)"

var_dump(hexdec("that")); // print "int(10)"
var_dump(hexdec("a0")); // print "int(160)"
?>