你瞧瞧是不是你要的:int x = 47802;//十进制整数,当然你的二进制可以容易地转换成十进制byte[] bytes = BitConverter.GetBytes(x);//将整数转换成四个字节
string s = Encoding.Default.GetString(bytes);//从字节获取字符串MessageBox.Show(s);运行的时候会弹出一个“汉”字。反过来: string s = "汉"; byte[] bytes = new byte[4]; Encoding.Default.GetBytes(s, 0, s.Length, bytes, 0); int m = BitConverter.ToInt32(bytes, 0); MessageBox.Show(m.ToString());运行时弹出“47802”
Encoding.Unicode.GetString()//unicode编码的话用这个
Encoding.UTF8.GetString()//utf8用这个
Encoding.GetEncoding("gb2312").GetString()//gb2312用这个
string str = "10110100111100111011110011010010101110101100001110110010110001011100101011000111110101011110011010110101110001001011101011000011";
byte[] bs = new byte[str.Length / 8];
int index = 0;
for (int i = 0; i < str.Length; i += 8)
{
bs[index++] = Convert.ToByte(str.Substring(i, 8), 2);
}
Console.WriteLine(HttpUtility.UrlDecode(bs, Encoding.GetEncoding("gb2312")));
/*
输出:
大家好才是真的好
*/
using System.Text;
using System.Web;
再麻烦您下,能告诉我HttpUtility.UrlDecode的命名空间是什么呢?我直接用提示:
当前上下文中不存在名称“HttpUtility”
string s = Encoding.Default.GetString(bytes);//从字节获取字符串MessageBox.Show(s);运行的时候会弹出一个“汉”字。反过来:
string s = "汉"; byte[] bytes = new byte[4]; Encoding.Default.GetBytes(s, 0, s.Length, bytes, 0); int m = BitConverter.ToInt32(bytes, 0); MessageBox.Show(m.ToString());运行时弹出“47802”