how do convert hexadecimal into ip javascript? - Stack Overflow

I need to convert a hexadecimal into equivalent IP in javascript?My hexadecial value is0A.0A.0A.0Aand

I need to convert a hexadecimal into equivalent IP in javascript?
My hexadecial value is
0A.0A.0A.0A
and i have to convert this into ip?
10.10.10.10

Please help me

I need to convert a hexadecimal into equivalent IP in javascript?
My hexadecial value is
0A.0A.0A.0A
and i have to convert this into ip?
10.10.10.10

Please help me

Share Improve this question asked Aug 3, 2011 at 6:55 DhineshDhinesh 111 silver badge4 bronze badges 1
  • Possible duplicate: stackoverflow./questions/57803/… – OverZealous Commented Aug 3, 2011 at 7:00
Add a ment  | 

4 Answers 4

Reset to default 4
var hex = "0A.0A.0A.0A";
var splitData = hex.split(".");
for (var i = 0; i < splitData.length; i++){
    splitData[i] = parseInt(splitData[i], 16);
}

var ip = splitData.join(".");
'0A.0A.0A.0A'.replace( /(\w{2})/gi, function( str, match ) {
    return parseInt( match, 16 );
});

You can use split, parseInt, and join to do most of the work:

addr  = '0A.0A.0A.0A';

// Break it into hex pieces.
parts = addr.split('.');

// Convert each piece to decimal using parseInt's radix argument.
for(var i = 0; i < parts.length; ++i)
    parts[i] = parseInt(parts[i], 16);

// And put it back together using join and implicit conversion
// of numbers to strings.
addr = parts.join('.');
// addr is now "10.10.10.10"

My two cents.

function ConvertHexIPToBase10(ip) {
    var vals = ip.split(".");
    var op = [];
    for (var i = 0; i < vals.length; i++) {
        op.push(parseInt(vals[i], 16));
    }
    return op.join(".");
}

var hexIP = "0A.0A.0A.0A";
var newIP = ConvertHexIPToBase10(hexIP);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744750424a4591559.html

相关推荐

  • how do convert hexadecimal into ip javascript? - Stack Overflow

    I need to convert a hexadecimal into equivalent IP in javascript?My hexadecial value is0A.0A.0A.0Aand

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信