176位到80位编码和解码的算法
我想要一个简单的算法,通过编码将 176 位压缩到 80 位,然后再从 80 位解码到 176 位?
I want a simple algorithm to compress 176 bit to 80 bit by encoding and decode it again from 80 bit to 176 bit ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于鸽洞原则,这是不可能完成的。
176 位可以表示的值有 9.5*10^52 个,但 80 位可以表示的值只有 1.2*10^24 个。您无法将每个 176 位值映射到 80 位值。
如果可能的话,您可以通过重复压缩将无限量的数据容纳在 80 位中。
话虽这么说,如果您对 176 位值有所了解,那么可能有办法做到这一点。假设您知道较大的值只有 22 个字面数字:例如“11223344556677889900”或“1111111111111111111111”等字符串。在这种情况下,可能的输入集将大大减少 - 并且您可以将每个值映射到 80 位值。
Because of the pigeonhole principle, it can't be done.
There are 9.5*10^52 different values that can be expressed in 176 bits, but there are only 1.2*10^24 different values that can be expressed in 80 bits. You can't map every 176 bit value to an 80-bit value.
If this were possible, you could fit an infinite amount of data in 80 bits by repeated compression.
That being said, if there's something you know about the 176-bit values, then there might be ways to do it. Say you know that the larger values would only ever 22 literal digits: e.g. strings like "11223344556677889900" or "1111111111111111111111". In this case, the possible set of inputs would be seriously reduced - and you'd be able to map each of those values to an 80 bit value.
那是不可能的。
176 位数字有 2^176 种不同的组合。不可能将这些组合中的每一种表示为不同的 80 位数字,该数字只有 2^80 种组合。这就像要求将 4 位数字压缩为 3 位数字然后再压缩回来一样。
根据您使用的数据类型,这可能会造成损失。介意解释一下你在做什么吗?
That isn't possible.
A 176 bit number has as 2^176 different combinations. It isn't possible to express each one of these combinations as a different 80 bit number, which only has 2^80 combinations. That's just like asking to compress a 4 digit number into a 3 digit number and back again.
Depending on what kind of data you're working with, this is possible with losses. Care to explain what you're doing?
如果您想自己实现,这里有一个相当简单的算法的描述:
http://en.wikipedia。 org/wiki/LZ77_and_LZ78
如果你更多地谷歌一下,有一个页面非常详细地解释了它在实践中是如何工作的,我现在找不到它。
或者,仅使用压缩库,例如
zlib
(http://en.wikipedia.org/wiki/Zlib)。Here is a description of a rather simple algorithm if you want to implement it yourself:
http://en.wikipedia.org/wiki/LZ77_and_LZ78
If you google more, there was a page with a very detailed explanation how it works in practice, I just can't find it right now.
Or, just use a compression library, for example
zlib
(http://en.wikipedia.org/wiki/Zlib).