int32 to IPv4

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function int32ToIp(int32){
if (int32 === 0) return "0.0.0.0";
var bits = int32.toString(2);
var ip = parseInt(bits.substring(0, 8), 2) + ".";
ip += parseInt(bits.substring(8, 16), 2) + ".";
ip += parseInt(bits.substring(16, 24), 2) + ".";
ip += parseInt(bits.substring(24, 32), 2);
return ip;
}