doudu2591 2014-12-21 19:26
浏览 44
已采纳

这是打包/解包吗?

I have this loop:

$encoded = '';
while ($number) {
  $encoded = chr($number & 0xFF) . $encoded;
  $number = $number >> 8;
}
return $encoded;

and I was wondering whether there's an equivalent pack or unpack for it.

  • 写回答

1条回答 默认 最新

  • dqd22496 2014-12-21 19:40
    关注

    You're encoding this as a big-endian representation (meaning most significant byte first), but with a variable width.

    So to get the bytes:

    pack("N", $number)
    

    You can also use 64 bit with J.

    But you also need to trim off leading null bytes (for variable width):

    ltrim(pack("N", $number), chr(0))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同
  • ¥15 excel 上下按钮 显示行
  • ¥20 云卓h12pro 数传问题
  • ¥20 请问有人知道怎么用工艺库里面的sdb文件通过virtuoso导出来library里面每个cell的symbol吗?
  • ¥20 海思 nnie 编译 报错
  • ¥50 决策面并仿真,要求有仿真结果图
  • ¥15 关于路由器的路由协议配置
  • ¥15 springboot接入微信支付SDK
  • ¥50 大区域的遥感影像匹配 怎么做啊
  • ¥15 求解答:pytorch跑yolov8神经网络受挫