请教各位是进制转十六进制问题,比如
string strToByte = "AA BB 01 01 01 01 01 50 37";
for (int j = 0; j <50; j++)
{
strToByte = strToByte.Replace(" ", "");
byte[] comBytes = new byte[strToByte.Length / 2];
for (int i = 0; i < comBytes.Length; i++)
{
comBytes[i] = Convert.ToByte(strToByte.Substring(i * 2, 2), 16);
}
int crc = (comBytes[0] + comBytes[1] + comBytes[2] + comBytes[3] + comBytes[4] + comBytes[5] + comBytes[6] + comBytes[7])-206;
string strByte = Convert.ToString(crc, 16);
Byte crcByte;
crcByte = Convert.ToByte(strByte, 16);
}
这样是可以转的,但我如果改掉第八个参数就是50,比如改45,算出来就不对了,我要每次循环,第八个参数每次递减5,一直到0结束,请问怎么转?
50的十六进制是80;
45的十六进制是69;
40的十六进制是28;
50一直递减到到0结束,请问怎么写的
string strToByte = "AA BB 01 01 01 01 01 50 37";
for (int j = 0; j <50; j++)
{
strToByte = strToByte.Replace(" ", "");
byte[] comBytes = new byte[strToByte.Length / 2];
for (int i = 0; i < comBytes.Length; i++)
{
comBytes[i] = Convert.ToByte(strToByte.Substring(i * 2, 2), 16);
}
int crc = (comBytes[0] + comBytes[1] + comBytes[2] + comBytes[3] + comBytes[4] + comBytes[5] + comBytes[6] + comBytes[7])-206;
string strByte = Convert.ToString(crc, 16);
Byte crcByte;
crcByte = Convert.ToByte(strByte, 16);
}
这样是可以转的,但我如果改掉第八个参数就是50,比如改45,算出来就不对了,我要每次循环,第八个参数每次递减5,一直到0结束,请问怎么转?
50的十六进制是80;
45的十六进制是69;
40的十六进制是28;
50一直递减到到0结束,请问怎么写的
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货