C# byte[] 转换16进制字符串
2021-02-13 09:16
标签:builder 字符 gets empty blog enc sub bytearray none 1.byte[] 转换16进制字符串 1.1 BitConverter方式 1.2 StringBuilder方式 2.16进制字符串转换 byte[] C# byte[] 转换16进制字符串 标签:builder 字符 gets empty blog enc sub bytearray none 原文地址:https://www.cnblogs.com/ycz109/p/8461151.html1 var str = DateTime.Now.ToString();
2 var encode = Encoding.UTF8;
3 var bytes = encode.GetBytes(str);
4 var hex = BitConverter.ToString(bytes, 0).Replace("-", string.Empty).ToLower();
5 Console.WriteLine(hex);
1 var str = DateTime.Now.ToString();
2 var encode = Encoding.UTF8;
3 var bytes = encode.GetBytes(str);
4 var hex = BitConverter.ToString(bytes, 0).Replace("-", string.Empty).ToLower();
5 Console.WriteLine(hex);
1 var inputByteArray = new byte[hex.Length / 2];
2 for (var x = 0; x )
3 {
4 var i = Convert.ToInt32(hex.Substring(x * 2, 2), 16);
5 inputByteArray[x] = (byte)i;
6 }
7 str = encode.GetString(inputByteArray);
8 Console.WriteLine(str);
文章标题:C# byte[] 转换16进制字符串
文章链接:http://soscw.com/index.php/essay/54811.html