private static byte[] hexStr2Bytes(String hex) { // Adding one byte to get the right conversion // Values starting with "0" can be converted byte[] bArray = new BigInteger("10" + hex, 16).toByteArray(); // Copy all the REAL bytes, not the "first" byte[] ret = new byte[bArray.length - 1]; for (int i = 0; i < ret.length; i++) ret[i] = bArray[i + 1]; return ret; }
解决方案
5
private static byte[] hexStr2Bytes(string strHex) { if(strHex.Length % 2 != 0) throw new Exception("...."); byte[] byRet = new byte[strHex.Length / 2]; for(int i = 0;i < byRet.Length; i++){ byRet[i] = Coverter.ToByte(strHex.SubString(i * 2,2),16); } return byRet; }
手打的 可能有误
5
private static byte[] hexStr2Bytes(String hex)
{
// Adding one byte to get the right conversion
// Values starting with “0” can be converted
byte[] bArray = BigInteger.Parse(“10” + hex, System.Globalization.NumberStyles.HexNumber).ToByteArray();
// Copy all the REAL bytes, not the “first”
byte[] ret = new byte[bArray.Length – 1];
for (int i = 0; i < ret.Length; i++)
ret[i] = bArray[i + 1];
return ret;
}
记得引用system.numerics.dll
{
// Adding one byte to get the right conversion
// Values starting with “0” can be converted
byte[] bArray = BigInteger.Parse(“10” + hex, System.Globalization.NumberStyles.HexNumber).ToByteArray();
// Copy all the REAL bytes, not the “first”
byte[] ret = new byte[bArray.Length – 1];
for (int i = 0; i < ret.Length; i++)
ret[i] = bArray[i + 1];
return ret;
}
记得引用system.numerics.dll
8
private static byte[] hexStr2Bytes(String hex)
{
return BigInteger.Parse(“10” + hex, NumberStyles.HexNumber)
.ToByteArray()
.Skip(1)
.ToArray();
}
哈,c#的功力不是java能比的。
{
return BigInteger.Parse(“10” + hex, NumberStyles.HexNumber)
.ToByteArray()
.Skip(1)
.ToArray();
}
哈,c#的功力不是java能比的。
2
哈哈,赞同