字符数组转换为字符串,字符串转换为字节

字符数组转换为字符串,字符串转换为字节,例子如下

                        char[] ch = new char[str1.Length];
                        for (int i = 0; i < str1.Length; i++)
                        {
                            ch[i] = str1[i];
                        }
                        byte[] data = new byte[str1.Length / 2 + 3];
                        for (int i = 0; i < str1.Length; i = i + 2)
                        {
                            string str2 = ch[i] + "" + ch[i + 1];
                            int int1 = Convert.ToInt32(str2, 16);
                            data[i / 2] = (Byte)int1;
                        }

 

posted @ 2021-11-10 10:32  代码不会写  阅读(401)  评论(0)    收藏  举报