最后分数谁给我把这段VB转成C#.NET
Public Function HEX_to_DEC(ByVal Hex As String) As Long
Dim I As Long
Dim b As Long
Hex = UCase(Hex)
For I = 1 To Len(Hex)
Select Case Mid(Hex, Len(Hex) - I + 1, 1)
Case "0 ": b = b + 16 ^ (I - 1) * 0
Case "1 ": b = b + 16 ^ (I - 1) * 1
Case "2 ": b = b + 16 ^ (I - 1) * 2
Case "3 ": b = b + 16 ^ (I - 1) * 3
Case "4 ": b = b + 16 ^ (I - 1) * 4
Case "5 ": b = b + 16 ^ (I - 1) * 5
Case "6 ": b = b + 16 ^ (I - 1) * 6
Case "7 ": b = b + 16 ^ (I - 1) * 7
Case "8 ": b = b + 16 ^ (I - 1) * 8
Case "9 ": b = b + 16 ^ (I - 1) * 9
Case "A ": b = b + 16 ^ (I - 1) * 10
Case "B ": b = b + 16 ^ (I - 1) * 11
Case "C ": b = b + 16 ^ (I - 1) * 12
Case "D ": b = b + 16 ^ (I - 1) * 13
Case "E ": b = b + 16 ^ (I - 1) * 14
Case "F ": b = b + 16 ^ (I - 1) * 15
End Select
Next I
HEX_to_DEC = b
End Function
[解决办法]
public long HEX_to_DEC(string Hex)
{
long I;
long b;
Hex = UCase(Hex);
for (int I = 1; I <= Len(Hex); I++) {
if (Mid(Hex, Len(Hex) - I + 1, 1) == "0 ") {
b = b + Math.Pow(16, (I - 1)) * 0;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "1 ") {
b = b + Math.Pow(16, (I - 1)) * 1;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "2 ") {
b = b + Math.Pow(16, (I - 1)) * 2;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "3 ") {
b = b + Math.Pow(16, (I - 1)) * 3;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "4 ") {
b = b + Math.Pow(16, (I - 1)) * 4;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "5 ") {
b = b + Math.Pow(16, (I - 1)) * 5;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "6 ") {
b = b + Math.Pow(16, (I - 1)) * 6;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "7 ") {
b = b + Math.Pow(16, (I - 1)) * 7;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "8 ") {
b = b + Math.Pow(16, (I - 1)) * 8;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "9 ") {
b = b + Math.Pow(16, (I - 1)) * 9;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "A ") {
b = b + Math.Pow(16, (I - 1)) * 10;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "B ") {
b = b + Math.Pow(16, (I - 1)) * 11;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "C ") {
b = b + Math.Pow(16, (I - 1)) * 12;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "D ") {
b = b + Math.Pow(16, (I - 1)) * 13;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "E ") {
b = b + Math.Pow(16, (I - 1)) * 14;
} else if (Mid(Hex, Len(Hex) - I + 1, 1) == "F ") {
b = b + Math.Pow(16, (I - 1)) * 15;
}
}
HEX_to_DEC = b;
}
[解决办法]
public long HEX_to_DEC(string Hex)
{
long I;
long b;
Hex = Microsoft.VisualBasic.Strings.UCase(Hex);
for (int I = 1; I <= Microsoft.VisualBasic.Strings.Len(Hex); I++)
{
if (Microsoft.VisualBasic.Strings.Mid(Hex, Microsoft.VisualBasic.Strings.Len(Hex) - I + 1, 1) == "0 ")
{
b = b + Math.Pow(16, (I - 1)) * 0;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "1 ")
{
b = b + Math.Pow(16, (I - 1)) * 1;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "2 ")
{
b = b + Math.Pow(16, (I - 1)) * 2;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "3 ")
{
b = b + Math.Pow(16, (I - 1)) * 3;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "4 ")
{
b = b + Math.Pow(16, (I - 1)) * 4;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "5 ")
{
b = b + Math.Pow(16, (I - 1)) * 5;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "6 ")
{
b = b + Math.Pow(16, (I - 1)) * 6;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "7 ")
{
b = b + Math.Pow(16, (I - 1)) * 7;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "8 ")
{
b = b + Math.Pow(16, (I - 1)) * 8;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "9 ")
{
b = b + Math.Pow(16, (I - 1)) * 9;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "A ")
{
b = b + Math.Pow(16, (I - 1)) * 10;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "B ")
{
b = b + Math.Pow(16, (I - 1)) * 11;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "C ")
{
b = b + Math.Pow(16, (I - 1)) * 12;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "D ")
{
b = b + Math.Pow(16, (I - 1)) * 13;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "E ")
{
b = b + Math.Pow(16, (I - 1)) * 14;
}
else if (Microsoft.VisualBasic.Strings.Mid(Hex, Len(Hex) - I + 1, 1) == "F ")
{
b = b + Math.Pow(16, (I - 1)) * 15;
}
}
HEX_to_DEC = b;
}
[解决办法]
result = long.Parse(hex, System.Globalization.NumberStyles.AllowHexSpecifier);
一条语句就能解决的问题...居然...
不看官方文档的程序员是愚蠢的...
缺乏想象力的程序员是可悲的...
[解决办法]
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx