擅长:python、mysql、java
<p>它本身并不是7位,但听起来像是<a href="https://docs.python.org/3/library/base64.html" rel="nofollow noreferrer"><em>base64</em> coding</a>的工作。如果您只需要通过7位通道传输数据,那么base64应该可以正常工作。当然,您的数据流将稍长一些,即6字节而不是5字节</p>
<p>下面是如何用Python编写它:</p>
<pre class="lang-py prettyprint-override"><code>import base64
def encode_number(n):
"""Takes an int and returns a bytes object in base64 encoding."""
return base64.b64encode(n.to_bytes(4, byteorder='little'))
def decode_number(b):
"""Takes a bytes object in base64 encoding and returns an int."""
return int.from_bytes(base64.b64decode(b), byteorder='little')
</code></pre>
<p>如果您需要超过32位的数字,只需更改第5行中的<code>4</code></p>