'Azure Log Analytics (Kusto) Convert from hex

Is there a way to convert from hex in Kusto? I see a scalar function to convert to hex, but I want to convert from hex.

https://docs.microsoft.com/en-us/azure/kusto/query/tohexfunction



Solution 1:[1]

you can use hex value for long literal, for example:

print long(0x123)

see more here: https://docs.microsoft.com/en-us/azure/kusto/query/scalar-data-types/long

Solution 2:[2]

(Posting to old thread if anyone finds this in the future.)

let T = datatable(Value:string) [
'A2FF',
'BEAD',
'CAFE',
'FACE',
'C0C0'
];
T
| extend ValueExtracted = extract_all('(.)', reverse(Value))
| mv-expand ValueExtracted
| serialize 
| extend ValueIndex = indexof('0123456789ABCDEF', ValueExtracted, 0)
| extend ValuePow = row_number(0, prev(Value) != Value)
| extend ValueDig = pow(16, ValuePow) * ValueIndex 
| summarize ValueComplete = sum(ValueDig) by Value 
| extend ToHexCalc = tohex(toint(ValueComplete))

Granted it isn't pretty but it seems to work for at least this data set. An inbuit function would be so much better I agree.

Output:

[Value, ValueComplete, ToHexCalc
A2FF, 41727, a2ff
BEAD, 48813, bead
CAFE, 51966, cafe
FACE, 64206, face
C0C0, 49344, c0c0][1]

Solution 3:[3]

Arriving late to the party...

0x
tolong()
make_string()

print character = make_string(tolong('0x22'))
character
"

Fiddle

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Avnera
Solution 2 Philippe Signoret
Solution 3