求2进制和16进制相互转换源码
------解决方案--------------------public static string ByteToHexstr(byte[] buff)
{
string result = "";
for (int i = 0; i < buff.Length; i++)
{
result += Convert.ToString(buff[i], 16) + " ";
}
return result.Trim().ToUpper();
}
public static byte[] HexstrToByte(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;
}
------解决方案--------------------一般16进制用字符,二进制不用字符的,如果二进制用字符,
public static byte[] HexstrToByte(string hexString)
你吧这个的结果转换一下就OK了
------解决方案--------------------refer: http://wenku.baidu.com/view/7d69cef4f61fb7360b4c65b5.html