2

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://learn.microsoft.com/en-us/azure/kusto/query/tohexfunction

Sean
  • 63
  • 1
  • 4

3 Answers3

1

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

print long(0x123)

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

Avnera
  • 7,088
  • 9
  • 14
  • I don't think that works as expected. For example 0x22 converts to a value of 34. I would like the value returned in ASCII. – Sean May 21 '19 at 15:18
  • Conversion from hex to ascii is not supported. Please open an [Azure Data Explorer (Kusto)user voice](https://feedback.azure.com/forums/915733-azure-data-explorer) item – Avnera May 22 '19 at 16:39
1

(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]
Philippe Signoret
  • 13,299
  • 1
  • 40
  • 58
  • While the effort is appreciated, this does not answer the question and should be deleted. P.S. there is much simpler way to achieve hex to dec conversion: `print hex = 'A2FF' | extend dec = toint(strcat('0x',hex))` – David דודו Markovitz May 15 '22 at 12:49
0

Arriving late to the party...

0x
tolong()
make_string()

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

Fiddle

David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88