//tempNum为10进制电压值
//转换规则:字符串转为2位16进制字符串,不够就补位
string x = this.DtoX(int.Parse(voltageValue)).PadLeft(4, '0');
//高位在前,低位在后
string maxVoltageHex = x.Substring(2, 2) + x.Substring(0, 2);
//十进制转十六进制
public string DtoX(int d)
{
string x = "";
if (d < 16)
{
x = Chang(d);
}
else
{
int c;
int s = 0;
int n = d;
int temp = d;
while (n >= 16)
{
s++;
n = n / 16;
}
string[] m = new string[s];
int i = 0;
do
{
c = d / 16;
m[i++] = Chang(d % 16); //判断是否大于10,如果大于10,则转换为A~F的格式
d = c;
} while (c >= 16);
x = Chang(d);
for (int j = m.Length - 1; j >= 0; j--)
{
x += m[j];
}
}
return x;
}