gpt4 book ai didi

在C中使用BCD压缩数字字符串id

转载 作者:行者123 更新时间:2023-11-30 15:02:28 25 4
gpt4 key购买 nike

我有一堆 id,其形式为 uint32_t-uint32_t 两个无符号整数,用连字符分隔。我正在寻找压缩它们。我正在考虑将它们转换为 BCD(即每个字节两位数字)并输出压缩字符串。例如,90-1418

90-1418 -> 0x39 0x00 0x2d 0x31 0x34 0x31 0x38
\ / | \ / \ /
0x90 0x2d 0x14 0x18

C 语言中是否有可以压缩/解压缩此类字符串的库?

最佳答案

您可以将数字存储为( ( num1 * Factor ) + num2 ) * 16 + Factor

001011000101010110100111
\/\_________/\_____/\__/
\ \ \ \___ The number of bits in first number (without leading zeros), padded to 4 bits.
\ \ \______ The first number in big-endian byte order.
\ \____________ The second number in big-endian byte order.
\______________________ Padding so the whole takes a multiple of 8 bits.

3 个字节。

最大 = 32+4+32+4 = 9 字节。

这总是会产生比你的更短的结果。

关于在C中使用BCD压缩数字字符串id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41048427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com