C#二进制与字符串之间的相互转换

时间:2023-01-11 20:47:30
C#二进制与字符串之间的相互转换
 1     /// <summary>
 2     /// 将字符串转成二进制
 3     /// </summary>
 4     /// <param name="s"></param>
 5     /// <returns></returns>
 6     public static string bianma(string s)
 7     {
 8         byte[] data = Encoding.Unicode.GetBytes(s);
 9         StringBuilder result = new StringBuilder(data.Length * 8);
10 
11         foreach (byte b in data)
12         {
13             result.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
14         }
15         return result.ToString();
16     }
C#二进制与字符串之间的相互转换
C#二进制与字符串之间的相互转换

将二进制转成 字符串

C#二进制与字符串之间的相互转换
C#二进制与字符串之间的相互转换
 1     /// <summary>
 2     /// 将二进制转成字符串
 3     /// </summary>
 4     /// <param name="s"></param>
 5     /// <returns></returns>
 6     public static string jiema(string s)
 7     {
 8         System.Text.RegularExpressions.CaptureCollection cs =
 9             System.Text.RegularExpressions.Regex.Match(s, @"([01]{8})+").Groups[1].Captures;
10         byte[] data = new byte[cs.Count];
11         for (int i = 0; i < cs.Count; i++)
12         {
13             data[i] = Convert.ToByte(cs[i].Value, 2);
14         }
15         return Encoding.Unicode.GetString(data, 0, data.Length);

//JS 进行计算自然年月季度周天数
  

var now = new Date();
//加五天.
var newDate = DateAdd("d ", 5, now);
alert(newDate.toLocaleDateString())
//加两个月.
newDate = DateAdd("m ", 2, now);
alert(newDate.toLocaleDateString())
//加一年
newDate = DateAdd("y ", 1, now);
alert(newDate.toLocaleDateString())

 
 


}
}


转载于: https://www.cnblogs.com/weihengblogs/archive/2013/12/23/3487257.html