Hex to Dec
Převod číselných soustav(16 -> 10)
java
užití v C#:
Console.WriteLine("3B0F".ToDec());
Console.WriteLine("FF".ToDec());
private static int ToDec(this string s)
{
Dictionary<char, int> dic = new Dictionary<char, int>()
{
{'0', 0},
{'1', 1},
{'2', 2},
{'3', 3},
{'4', 4},
{'5', 5},
{'6', 6},
{'7', 7},
{'8', 8},
{'9', 9},
{'A', 10},
{'B', 11},
{'C', 12},
{'D', 13},
{'E', 14},
{'F', 15},
};
int result = 0;
int n = s.Length -1;
foreach (var c in s)
result += (dic[c] * (int)Math.Pow(16,n--));
return result;
}
Neformátovaný
Přidáno: 14.12.2013
Expirace: Neuvedeno