c# 串口的使用 :ASSCII转换位16

方法1 : data是传入的ascii码数据,最后返还一个16进制的数据

        /// <summary>
        /// ASSCII转换位16
        /// </summary>
        /// <param name="data">ascii码</param>
        public object AsEncon(string data) {
            byte[] ba = System.Text.ASCIIEncoding.Default.GetBytes(data);
            StringBuilder sb = new StringBuilder();
            foreach (byte b in ba)           {
                sb.Append(b.ToString("x")+" ");
            }
            //conPrint("AsEncon  转换16hex:" + sb);
           return sb;
        }

 

posted @ 2018-03-14 23:34  Black-Hs  阅读(391)  评论(0编辑  收藏  举报