C# Byte[] 转String 无损转换
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# Byte[] 转String 无损转换相关的知识,希望对你有一定的参考价值。
C# Byte[] 转String 无损转换
转载请注明出处 http://www.cnblogs.com/Huerye/
/// <summary> /// string 转成byte[] /// </summary> /// <param name="hexString"></param> /// <returns>byte[]</returns> private byte[] strToToHexByte(string hexString) { hexString = hexString.Replace(" ", ""); if ((hexString.Length % 2) != 0) hexString += " "; byte[] returnBytes = new byte[hexString.Length / 2]; for (int i = 0; i < returnBytes.Length; i++) returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); return returnBytes; } /// <summary> /// byte[] 转string /// </summary> /// <param name="bytes"></param> /// <returns>string</returns> public string byteToHexStr(byte[] bytes) { string returnStr = ""; if (bytes != null) { for (int i = 0; i < bytes.Length; i++) { returnStr += bytes[i].ToString("X2"); } } return returnStr; }
以上是关于C# Byte[] 转String 无损转换的主要内容,如果未能解决你的问题,请参考以下文章