字节数组(byte[])与16进制字符串转换
程序员文章站
2022-06-10 17:53:31
1 /// 2 /// 转换扩展类 3 /// 4 public static class ConvertExtend 5 { 6 /// 7 /// 将byte[]转换为16进制字符串 8 /// 9 ///
1 /// <summary> 2 /// 转换扩展类 3 /// </summary> 4 public static class convertextend 5 { 6 /// <summary> 7 /// 将byte[]转换为16进制字符串 8 /// </summary> 9 /// <param name="bytes"></param> 10 /// <returns></returns> 11 public static string tostring16(this byte[] bytes) 12 { 13 return bytes.tolist().tostring16(); 14 } 15 16 /// <summary> 17 /// 将list<byte>转换为16进制字符串 18 /// </summary> 19 /// <param name="bytes"></param> 20 /// <returns></returns> 21 public static string tostring16(this list<byte> bytes) 22 { 23 return string.join(" ", bytes.convertall(b => convert.tostring(b, 16))); 24 } 25 26 /// <summary> 27 /// 将16进制字符串转换为byte[] 28 /// </summary> 29 /// <param name="str16"></param> 30 /// <returns></returns> 31 public static byte[] tobyte(this string str16) 32 { 33 return str16.split(' ').tolist().convertall(s => convert.tobyte(s, 16)).toarray(); 34 } 35 }
上一篇: MYSQL创建数据库时指定编码
下一篇: 琵琶腿和鸡腿的区别,不知道你快来看看吧