本文介绍了如何从8位字节转换为7位字节(基地256到基地128)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从8位字节转换为7位字节(基地256到基地128)

How do I convert from 8 bit byte to 7 bit byte (Base 256 to Base 128)

我希望做这样的事情:

public string BytesToString(byte[] in)
{

}

public byte[] StringToBytes(string in)
{

}

我知道的base64可用,但它展开一个字节数组太多了。

I know base64 is available but it expands a byte array too much.

推荐答案

的Base64编码每个字符6位,生产。它可以用很少的努力(模并注意URL)的可靠传输的字符串

Base64 encodes 6 bits per character, producing a string which can be reliably transmitted with very little effort (modulo being careful about URLs).

有没有7位字母相同性质的 - 很多的许多的,如果他们给出的控制字符,例如系统会失败。

There is no 7-bit alphabet with the same properties - many, many systems will fail if they're given control characters, for example.

您的绝对保证的你是不会需要经过任何这样的系统(包括用于存储)?它节省空间真的足以证明不必担心是否东西都不会改变\\\
到\r\\\
(反之亦然),或删除字符0?

Are you absolutely sure that you're not going to need to go through any such systems (including for storage)? It the extra tiny bit of space saving really enough to justify having to worry about whether something's going to change "\n" to "\r\n" or vice versa, or drop character 0?

(对于存储例如,2100字节= 2800字符以base64或2400个字符的base128,不是一个巨大的差异IMO)

(For a storage example, 2100 bytes = 2800 chars in base64, or 2400 chars in base128. Not a massive difference IMO.)

我强烈敦促你,看你是否能找到额外的存储空间 - 它很可能以后节省很多麻烦

I'd strongly urge you to see whether you can find the extra storage space - it's likely to save a lot of headaches later.

这篇关于如何从8位字节转换为7位字节(基地256到基地128)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 18:22