2

我有一组 6 位代表 7 位 ASCII 字符。如何从我拥有的 6 位中获得正确的 7 位 ASCII 码?只需附加一个零并执行按位或?

谢谢你的帮助。

伦纳特

4

5 回答 5

8

ASCII 本质上是一个 7 位字符集,所以你所拥有的不是“6 位 ASCII”。哪些角色构成了您的角色集?最简单的解码方法可能是这样的:

char From6Bit( char c6 ) {
    // array of all 64 characters that appear in your 6-bit set
    static SixBitSet[] = { 'A', 'B', ... }; 
    return SixBitSet[ c6 ];
}   

脚注:6 位字符集在旧的 DEC 硬件上非常流行,其中一些,如 DEC-10,具有 36 位架构,其中 6 位字符有意义。

于 2009-04-20T13:15:12.037 回答
2

您必须告诉我们您的 6 位字符集的外观,我认为没有标准。

进行反向映射的最简单方法可能是只使用查找表,如下所示:

static const char sixToSeven[] = { ' ', 'A', 'B', ... };

这假设空间编码为(二进制)000000,大写 A 编码为 000001,依此类推。

sixToSeven您使用其中一个 6 位字符进行索引,然后取回本地 7 位字符。

于 2009-04-20T13:16:59.397 回答
2

I can't imagine why you'd be getting old DEC-10/20 SIXBIT, but if that's what it is, then just add 32 (decimal). SIXBIT took the ASCII characters starting with space (32), so just add 32 to the SIXBIT character to get the ASCII character.

于 2009-04-20T13:51:35.007 回答
1

The only recent 6-bit code I'm aware of is base64. This uses four 6-bit printable characters to store three 8-bit values (6x4 = 8x3 = 24 bits).

The 6-bit values are drawn from the characters:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

which are the values 0 thru 63. Four of these (say UGF4) are used to represent three 8-bit values.

UGF4 = 010100 000110 000101 111000
     = 01010000 01100001 01111000
     = Pax

If this is how your data is encoded, there are plenty of snippets around that will tell you how to decode it (and many languages have the encoder and decoder built in, or in an included library). Wikipedia has a good article for it here.

If it's not base64, then you'll need to find out the encoding scheme. Some older schemes used other lookup methods of the shift-in/shift-out (SI/SO) codes for choosing a page within character sets but I think that was more for choosing extended (e.g., Japanese DBCS) characters rather than normal ACSII characters.

于 2009-04-20T13:41:21.427 回答
0

如果我要给你一个比特的值,并且我声称它是从 Windows XP 中获取的,你能重建整个操作系统吗?

你不能。你丢失了信息。除非您对丢失的内容有所了解,否则无法重建它。如果您知道,例如,最高有效位被切断,那么您可以将其设置为零,并且您已经正确地重建了至少一半的字符。

如果您知道 'a' 和 'z' 在 6 位编码中是如何表示的,则可以通过将它们与它们的 7 位表示进行比较来猜测删除的内容。

于 2009-04-20T13:19:33.617 回答