Convert string to binary and binary to string in C#

String to binary method:

 public static string StringToBinary(string data)
{
StringBuilder sb = new StringBuilder(); foreach (char c in data.ToCharArray())
{
sb.Append(Convert.ToString(c, ).PadLeft(, ''));
}
return sb.ToString();
}

Binary to string method:

 public static string BinaryToString(string data)
{
List<Byte> byteList = new List<Byte>(); for (int i = ; i < data.Length; i += )
{
byteList.Add(Convert.ToByte(data.Substring(i, ), ));
}
return Encoding.ASCII.GetString(byteList.ToArray());
}
上一篇:你的MySQL服务器开启SSL了吗?


下一篇:四则运算 Java 杨辉鹏,郑冠华