如何将ascii代码转换为位数组 [英] how to convert a ascii code to bit array

查看:103
本文介绍了如何将ascii代码转换为位数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在图像隐写中,输入的文本被转换为等效的ascii,并且ascii被转换为字节并再次转换为字节数组...如何在vb.net?

In image steganography the inputted text is converted into equivalent ascii and that ascii is converted into byte and again byte to bit array...How can i do this in vb.net?

推荐答案

在一般情况下,文本无法转换为ASCII,因为.NET支持Unicode,而ASCII仅支持代码点低于127的Unicode字符。



只要忘记ASCII ,它就消失了;使用任何UTF编码。



请记住它们都是等价的,但产生的二进制代码是不同的(在内存中,Unicode使用UTF16LE表示)。这不是一个数组,而是字节数组。 (无论如何你永远不需要一个阵列)。您需要使用 System.Text.Encoding.ToBytes(string)来获取字节数组和 System.Text.Encoding.GetChars 再次返回字符串(使用结果char数组作为字符串的参数构造函数:



http://msdn.microsoft.com/en-us/library/ds4kkd55.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/khac988h.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ system.text.encoding.aspx [ ^ ],

http://msdn.microsoft.com/en -us / library / ttyxaek9.aspx [ ^ ]。



当然,您需要使用从抽象类派生的具体UTF类之一编码;我更喜欢UTF-8作为最紧凑的,特别是如果您的文本的许多字符都使用ASCII 保留曲目,这是最典型的情况。此外,这个UTF是大多数应用领域的标准。



-SA
In general case, the text cannot be "converted" into ASCII, because .NET supports Unicode, and ASCII only supports Unicode characters with code points below 127.

Just forget ASCII, it''s gone; use any of the UTF encodings.

Remember that they are all equivalent, but resulting binary code is different (in memory, Unicode is represented using UTF16LE). And this is not a bit array, but array of bytes. (You never need a bit array anyway). You need to use System.Text.Encoding.ToBytes(string) to get byte array and System.Text.Encoding.GetChars to go back to string again (use resulting char array as the argument of a string constructor:

http://msdn.microsoft.com/en-us/library/ds4kkd55.aspx[^],
http://msdn.microsoft.com/en-us/library/khac988h.aspx[^],
http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx[^],
http://msdn.microsoft.com/en-us/library/ttyxaek9.aspx[^].

Of course, you will need to use one of concrete UTF classes derived from the abstract class Encoding; I would prefer UTF-8 as the most compact, especially if many characters of your text are withing the ASCII repertoire, which is most typically the case. Also, this UTF is the standard for most application fields.

—SA


这篇关于如何将ascii代码转换为位数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆