public byte[] stringToBytes(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[(i / 2)] = ((byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)));
}
return data;
}
public byte[] StrToByte(string str)
{
object[] arg= new object[1];
int i = 0;
arg[0] = str;
int length = str.Length;
byte[] array = new byte[length / 2];
while (i < length)
{
array[i / 2] = Convert.ToByte((Convert.ToInt32(str[i].ToString(), 16) << 4) + Convert.ToInt32(str[i + 1].ToString(), 16));
i += 2;
}
return array;
}
我C#是这样翻译的
但是传入“3abcdef123”
java输出[58, -68, -34, -15, 35]
C#输出[58, 188, 222, 241, 35]
求问如何让C#输出和java一样的值