• C#字符串二进制互换


    static void Main(string[] args)         {             string str = "宋军辉";             Console.WriteLine(bianma(str));             string str1 = bianma(str);             Console.WriteLine(jiema(str1.Substring(0,16)));             Console.Read();         }         /// <summary>         /// 将 字符串 转成 二进制 “10011100000000011100011111111101”         /// </summary>         /// <param name="s"></param>         /// <returns></returns>         public static string bianma(string s)         {             byte[] data = Encoding.Unicode.GetBytes(s);             StringBuilder result = new StringBuilder(data.Length * 8);

                foreach (byte b in data)             {                 result.Append(Convert.ToString(b, 2).PadLeft(8, '0'));             }             return result.ToString();         }         /// <summary>         /// 将二进制 “10011100000000011100011111111101” 转成 字符串         /// </summary>         /// <param name="s"></param>         /// <returns></returns>         public static string jiema(string s)         {             System.Text.RegularExpressions.CaptureCollection cs =                 System.Text.RegularExpressions.Regex.Match(s, @"([01]{8})+").Groups[1].Captures;             byte[] data = new byte[cs.Count];             for (int i = 0; i < cs.Count; i++)             {                 data[i] = Convert.ToByte(cs[i].Value, 2);             }             return Encoding.Unicode.GetString(data, 0, data.Length);         }

  • 相关阅读:
    1+x LNMP + WordPress
    1+X Samba
    1+X NFS
    1+x FTP
    1+x LVM
    笔记(全)
    前端性能优化整理总结
    Event Loop我知道,宏任务微任务是什么鬼?
    深入探讨深拷贝浅拷贝两兄弟
    react后台管理系统路由方案及react-router原理解析
  • 原文地址:https://www.cnblogs.com/armyfai/p/3547793.html
Copyright © 2020-2023  润新知