Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
realpixel
New Contributor III

Convert HEX value to IP address

Hello,

On my chart, I have a column "SourceIP" with Hexadecimal value, like "0A5C0158", if I convert manualy this value to decimal I obtain 10.92.1.88 now I want to know if there are a possibility to convert all value in my chart from HEX to IP address, someone have an idea?

1 Solution

Accepted Solutions

Re: Convert HEX value to IP address

You def. don't want to use static value in your chart, that was just an example. This is what you need:

=Num(Num#(Left(Num(Num#(SourceIP, '(HEX)'), '(BIN)'), Len(Num(Num#(SourceIP, '(HEX)'), '(BIN)')) - 24), '(BIN)'))&'.'&

Num(Num#(Mid(Num(Num#(SourceIP, '(HEX)'), '(BIN)'), Len(Num(Num#(SourceIP, '(HEX)'), '(BIN)')) - 23, 8), '(BIN)'))&'.'&

Num(Num#(Mid(Num(Num#(SourceIP, '(HEX)'), '(BIN)'), Len(Num(Num#(SourceIP, '(HEX)'), '(BIN)')) - 15, 8), '(BIN)'))&'.'&

Num(Num#(Right(Num(Num#(SourceIP, '(HEX)'), '(BIN)'), 8), '(BIN)'))

10 Replies

Re: Convert HEX value to IP address

May be this:

=Num(Num#(Left(Num(Num#('0A5C0158', '(HEX)'), '(BIN)'), Len(Num(Num#('0A5C0158', '(HEX)'), '(BIN)')) - 24), '(BIN)'))&'.'&

Num(Num#(Mid(Num(Num#('0A5C0158', '(HEX)'), '(BIN)'), Len(Num(Num#('0A5C0158', '(HEX)'), '(BIN)')) - 23, 8), '(BIN)'))&'.'&

Num(Num#(Mid(Num(Num#('0A5C0158', '(HEX)'), '(BIN)'), Len(Num(Num#('0A5C0158', '(HEX)'), '(BIN)')) - 15, 8), '(BIN)'))&'.'&

Num(Num#(Right(Num(Num#('0A5C0158', '(HEX)'), '(BIN)'), 8), '(BIN)'))


Capture.PNG

realpixel
New Contributor III

Re: Convert HEX value to IP address

Hello,

Thank you for your reply but it's works only for value  '0A5C0158' but not for other value in my chart.

I have a column named "SourceIP" all value are in HEX and I want to convert there défirent value to IP addess.

Re: Convert HEX value to IP address

Can you share few other values for where it isn't working?

realpixel
New Contributor III

Re: Convert HEX value to IP address

For example the value 0A5C0A64 (10.92.10.100) have same IP (10.92.1.88) like the value '0A5C0158'

Re: Convert HEX value to IP address

Not sure what the issue is. It seem to work for both the values for me:

Capture.PNG

Re: Convert HEX value to IP address

Not sure where you are doing this, but replace all the red places with your new Hex Code:

=Num(Num#(Left(Num(Num#('0A5C0158', '(HEX)'), '(BIN)'), Len(Num(Num#('0A5C0158', '(HEX)'), '(BIN)')) - 24), '(BIN)'))&'.'&

Num(Num#(Mid(Num(Num#('0A5C0158', '(HEX)'), '(BIN)'), Len(Num(Num#('0A5C0158', '(HEX)'), '(BIN)')) - 23, 8), '(BIN)'))&'.'&

Num(Num#(Mid(Num(Num#('0A5C0158', '(HEX)'), '(BIN)'), Len(Num(Num#('0A5C0158', '(HEX)'), '(BIN)')) - 15, 8), '(BIN)'))&'.'&

Num(Num#(Right(Num(Num#('0A5C0158', '(HEX)'), '(BIN)'), 8), '(BIN)'))

realpixel
New Contributor III

Re: Convert HEX value to IP address

Yes, If I replace '0A5C0158' by '0A5C0A64' it's works but all value in my chart have the same IP address '10.92.10.100'

Maybe the solution, it's to split the column "SourceIP" (AABBCCDD)

To have AA in new field like "HEXIP1"

BB in new field like "HEXIP2"

CC in new field like "HEXIP3"

DD in new field like "HEXIP4"

And after convert HEXIP1, HEXIP2, HEXIP3 and HEXIP4 from Hex to decimal to new other field as DECIP1, DECIP2, DECIP3, DECIP4

And to finish concatenate DECIP1+DECIP2+DECIP3+ECIP4 to have the final result

DECIP1.ECIP2.DECIP3.DCIP4

Re: Convert HEX value to IP address

You def. don't want to use static value in your chart, that was just an example. This is what you need:

=Num(Num#(Left(Num(Num#(SourceIP, '(HEX)'), '(BIN)'), Len(Num(Num#(SourceIP, '(HEX)'), '(BIN)')) - 24), '(BIN)'))&'.'&

Num(Num#(Mid(Num(Num#(SourceIP, '(HEX)'), '(BIN)'), Len(Num(Num#(SourceIP, '(HEX)'), '(BIN)')) - 23, 8), '(BIN)'))&'.'&

Num(Num#(Mid(Num(Num#(SourceIP, '(HEX)'), '(BIN)'), Len(Num(Num#(SourceIP, '(HEX)'), '(BIN)')) - 15, 8), '(BIN)'))&'.'&

Num(Num#(Right(Num(Num#(SourceIP, '(HEX)'), '(BIN)'), 8), '(BIN)'))

realpixel
New Contributor III

Re: Convert HEX value to IP address

Great, thank you very much, it works

Community Browser