cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to convert hexadecimal ip address to standard ipv4 address

ycot
Node Link

Hello!

I'm currently trying to convert hexadecimal ip address into A.B.C.D format.

This ip field is a string "0a0a0b43" for exemple and the result has to be 10.10.11.67
I've done some attempts but whitout success...

By advance, thanks you

1 ACCEPTED SOLUTION
4 REPLIES 4

Hi,

There are some libraries in java which can convert hex to string and you may use that.
And then you can make a user defined function of it.
java example:

public static String convertHexToIP(String hex)
{
    String ip= "";

    for (int j = 0; j < hex.length(); j+=2) {
        String sub = hex.substring(j, j+2);
        int num = Integer.parseInt(sub, 16);
        ip += num+".";
    }

    ip = ip.substring(0, ip.length()-1);
    return ip;
}

a more generic approach is described here: https://www.mkyong.com/java/how-to-convert-hex-to-ascii-in-java/

Does this help you?

regards
Kees

Hi Kees,

Thanks you for your quickness!
I think it will be good, i've just to find how to create and use user-defined java procedures in Neo4j

Regards
Yann

Thanks you very much Kees!

Have a nice day