【问题标题】:Who remember the algorithm to pack 4-bytes integer to array of 1-to-4 bytes depending from number of significant digits?谁记得根据有效位数将 4 字节整数打包为 1 到 4 字节数组的算法?
【发布时间】:2019-05-26 22:03:34
【问题描述】:

我需要一种有效的算法或想法来将 4 字节整数打包成尽可能短的字节数组。例如,我可以将 0x00000000 到 0x0000007f 的值打包到一字节数组中,只是假设 bit7=0 表示 1 字节长度。 如果我有 128 或更长的数字,我需要发明更智能的东西来打包成 2 字节数组、3 字节数组等。

谁记得这个算法?请分享。

【问题讨论】:

    标签: arrays algorithm binary packing


    【解决方案1】:

    变长数量:https://en.wikipedia.org/wiki/Variable-length_quantity

    UTF-8 也使用它。

    【讨论】:

      猜你喜欢
      • 2014-10-27
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 2015-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多