Skip to content

Instantly share code, notes, and snippets.

@tsaniel
Forked from 140bytes/LICENSE.txt
Created January 19, 2012 10:48
Show Gist options
  • Save tsaniel/1639378 to your computer and use it in GitHub Desktop.
Save tsaniel/1639378 to your computer and use it in GitHub Desktop.
PHPJS - long2ip
function(
a // input for a number
) {
return
1 << -1 <= a // if the number greater than or equal to -2147483648
&& // then
a < 4294967296 // if the number less than or equal to 42949672945
&& // then
[
a >>> 24, // calculate the first octet
255 & a >>> 16, // calculate the second octet
255 & a >>> 8, // calculate the third octet
255 & a // calculate the fourth octet
].join('.') // combine the octets into dot-decimal notation
}
function(a){return 1<<-1<=a&&a<4294967296&&[a>>>24,255&a>>>16,255&a>>>8,255&a].join('.')}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "long2ip",
"description": "Converts an (IPv4) Internet network address into a string in Internet standard dotted format.",
"keywords": [
"ip",
"phpjs",
"ip2long",
"long2ip",
"octet"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>0.0.0.0,127.255.255.255,192.168.1.2,192.168.1.2,false,false</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var myFunction = function(a){return 1<<-1<=a&&a<4294967296&&[a>>>24,255&a>>>16,255&a>>>8,255&a].join('.')}
document.getElementById( "ret" ).innerHTML =
[myFunction(0),
myFunction(2147483647),
myFunction(-1062731518),
myFunction(3232235778),
myFunction(42949672946),
myFunction(-2147483649)
]
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment