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.
long2ip: https://gist.github.com/1639378
Genius! I didn't know the bitwise shift operator accepts negative numbers before.
By using this trick, we are able to put the increment of the index outside, thus there will be no infinitive loop any more, so
b=
is not needed.Awesome!, @subzey!
By the way, I use parseInt to convert numbers so octal numbers are supported now.