Answers for "function int32ToIp(int32)"

0

function int32ToIp(int32)

function int32ToIp(int32){
    let int2 = int32.toString(2),
        len = 32 - int2.length,
        begins = [0,8,16,24],
        ipArr = [];

    if (len) {
        int2 += Array(len + 1).join('0')
    }

    begins.forEach((begin) => {
        ipArr.push(Number.parseInt(int2.slice(begin,begin + 8),2))
    })

    return ipArr.join('.');
}
console.log(int32ToIp(2154959208))
console.log(int32ToIp(0))
console.log(int32ToIp(2149583361))
console.log(int32ToIp(32))
Posted by: Guest on October-15-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language