MQTT中的Remaining Length,最大长度为4个字节。
其中每个字节的第一位为 “是否有后续字节” 的状态位。
如果有设置该状态位为1,没有则设置为0。
估可用小于或等于4个字节来表示 MQTT包的长度(该4位不计入在包大小范围,因此忽略计入)。
<?php
function numerical2Binary($number)
{
$char = [];
$first = 0;
$next = $number;
$key = 0;
do {
$first = $next % 128;
$next = intval($next / 128);
$char[$key] = $first;
if ($next > 0) {
$char[$key] |= 0x80;
}
++$key;
} while($next > 0);
return $char;
}
$result = numerical2Binary(321);
foreach ($result as $key => $value) {
printf("%08b \n", $value);
}
————————————————
原文链接:https://blog.csdn.net/technofiend/article/details/53746904