我有一個2字節長的十六進制字符串,需要將第一個字節按位移到左邊,然後向它添加第二個字節。兩個字符串都來自32個字符的字符串。字符串來自我正在解析的數據文件。你如何在PHP中按位移動數據類型字符串的十六進制字符串?
$hex="05E000752F0100D0A500503891FB199A"; //example line of data from file
$vcanvbatt=(base_convert(((base_convert(substr($hex,12,2),16,2)<<8)+base_convert(substr($hex,14,2),16,2)),2,10))/100;
'$ byte1 = hexdec(substr(...)); $ byte2 = hexdec(substr(...)); $ result =($ byte1 << 8)+ $ byte2;'? – DCoder
@DCoder你應該發佈,作爲答案 –