好的,所以我有一个带整数的数组(从intel Hex文件转换而来),需要输出为二进制。
这是文件阅读器,但如何将数组转换回字节流(utf-8)?
$filename = "./latest/firmware.hex";
$file = fopen($filename, "r");
$image = array();
$imagesize = 0;
$count = 0;
$address = 0;
$type = 0;
while(!feof($file))
{
$line = fgets($file);
$count = intval(substr($line,1,2));
$address = intval(substr($line,3,4));
$type = intval(substr($line,7,2));
if($type==0)
{
for ($i=0; $i < $count; $i++) {
$image[$address+1] = intval(substr($line,9+$i*2,2));
if (($address + $i) > $imagesize)
{
$imagesize = $address + $i;
}
}
}
else if($type == 1)
{
break;
}
}