Kirix Support Forums

Convert Hex to decimal (for IP address)

Please post any help questions, requests or other feedback here.

Convert Hex to decimal (for IP address)

Postby cjbaccus on Mon Mar 25, 2013 12:15 pm

I am getting SNMP data for a system that I manage, and need to put together reports monthly. The database stores the IP address information in Hex... so an example would be "C0 A8 01 01"
What would be the best way to convert this to a dotted decimal format: "192.168.1.1"?
Any ideas or help would be very much appreciated.
Thanks,
--Carl
cjbaccus
Registered User
 
Posts: 4
Joined: Thu May 21, 2009 9:21 am

Re: Convert Hex to decimal (for IP address)

Postby Ben on Wed Mar 27, 2013 8:56 am

I had a little fun and coded it for you :-)


Code: Select all
function convertHexToDecIP(str)
{
    var i, ret = '', parts = str.split(" ");
    for (i = 0; i < parts.length; ++i)
    {
        if (i > 0)
            ret += '.';
        ret += parseInt(parts[i], 16);
    }
    return ret;
}

print(convertHexToDecIP("C0 A8 01 01"));
Ben Williams
Kirix Support Team
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Re: Convert Hex to decimal (for IP address)

Postby cjbaccus on Fri Mar 29, 2013 12:32 pm

YOU ROCK BEN!!!!
Thank You Very Very much! That has given me ideas on how to do several other functions too!! :P
cjbaccus
Registered User
 
Posts: 4
Joined: Thu May 21, 2009 9:21 am

Return to Strata Help & Feedback