0x开头的16进制没有负数与小数
private double hexconvertodouble(string hexstring) 【相关文章:十个必备的.NET开发小工具(9 &am】
#region change hex to double 【扩展阅读:十个必备的.NET开发小工具(8):NA】
if (hexstring == "") 【扩展信息:开发基于J2EE,Struts和SQL 】
{
{
return 0;
}
string data;
if (hexstring.startswith("0x"))
{
data = hexstring.substring(2);
}
else
{
data = hexstring;
}
char[] eachdata = data.tochararray();
double result = 0;
for (int i = 0; i < eachdata.length; i++)
{
char charvalue = eachdata[i];//eachdata[m];
double x = 16;//如果是八进制则写成8就可以
double y = system.convert.todouble(eachdata.length - i - 1);
switch (charvalue)
{
case ´0´:
break;
case ´1´:
result += 1 * math.pow(x,y);
break;
case ´2´:
result += 2 * math.pow(x,y);
break;
case ´3´:
result += 3 * math.pow(x,y);
break;
case ´4´:
result += 4 * math.pow(x,y);
break;
case ´5´:
result += 5 * math.pow(x,y);
break;
case ´6´:
result += 6 * math.pow(x,y);
break;
case ´7´:
result += 7 * math.pow(x,y);
break;
case ´8´:
result += 8 * math.pow(x,y);
break;
case ´9´:
result += 9 * math.pow(x,y);
break;
case ´a´:
result += 10 * math.pow(x,y);
break;
case ´b´:
result += 11 * math.pow(x,y);
break;
case ´c´:
... 下一页