Forum Discussion
JFAschoon
Helper I
2 years agoConverting Hexadecimal to Decimal
Good all. Ive got the following syntex to convert a 2 digit HexaDecimal(2E) to Decimal value which works 100% fine. Know im sitting with a 4 digit HexaDecimal(d2da) in a column which i would li...
Ahmedx
Super User
2 years agoupdated fanction
(HextoDecimal) =>
List.Sum(
[
t = Splitter.SplitTextByRepeatedLengths(1)(HextoDecimal),
dict = List.Buffer(
{
{"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"}
}
),
f = (x) => List.Accumulate(dict, x, (s, c) => Text.Replace(s, c{0}, c{1})),
ListTrans = List.Transform(t, (x) => f(x)),
ListPower = List.Generate(() => List.Count(t) - 1, (x) => x >= 0, (x) => x - 1),
ListDecimal = Table.FromColumns({ListTrans, ListPower}, {"decimal", "Power"}),
addColumn = Table.AddColumn(
ListDecimal,
"DecimalSum",
each Number.From([decimal]) * Number.Power(16, [Power])
)[DecimalSum]
][addColumn]
)