Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address.
The function works with the following notation:
- Dot-decimal notation (
192.0.2.235
) - Dotted Hexadecimal (
0xC0.0x00.0x02.0xEB
) - Dotted Octal (
0300.0000.0002.0353
) - Multiple notation (
192.0x00.0002.0353
)
The function will try to parse any inputs, so a non-complete address (10.0.0
) also works; it will return NaN
if the input is an invalid address.
Very nice
-256 & d
trick, bravo, @tsaniel!Few more tricks can make this code 6 bytes shorter:
function(a,b,c,d){for(c=b=0;d=a.split('.')[b++];)c+=-256&d|b>4?NaN:d*(1<<-8*b);return c}