<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Convert an IP address to IP number with PHP, ASP, C# and VB.Net</title>
	<atom:link href="http://www.justin-cook.com/wp/2006/11/28/convert-an-ip-address-to-ip-number-with-php-asp-c-and-vbnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.justin-cook.com/wp/2006/11/28/convert-an-ip-address-to-ip-number-with-php-asp-c-and-vbnet/</link>
	<description>A web, technology, programming and SEO blog by Justin Cook</description>
	<pubDate>Sun, 12 Oct 2008 00:41:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Nick Critten</title>
		<link>http://www.justin-cook.com/wp/2006/11/28/convert-an-ip-address-to-ip-number-with-php-asp-c-and-vbnet/#comment-148727</link>
		<dc:creator>Nick Critten</dc:creator>
		<pubDate>Thu, 25 Sep 2008 12:19:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.justin-cook.com/wp/2006/11/28/convert-an-ip-address-to-ip-number-with-php-asp-c-and-vbnet/#comment-148727</guid>
		<description>@Ashley Sheridan

This is incorrect, a negative numbered IP number is simply an indication that the wrong datatype is being used to store it.
IP Addresses are actually a 32bit binary number, in decimal these are values between 0 (0.0.0.0) and 4294967295 (255.255.255.255)

On 32Bit Computer Systems (i.e. most PCs &#38; servers out there today), an UNSIGNED integer value has the range 0-4294967295. A SIGNED Interger will have the range −2147483648 to +2147483647.  This is because 1 bit is "Wasted" as the sign.

However PHP (for reasons that are completely beyond me) doesn't support unsigned integers.  For this reason, IP numbers in PHP *should* be stored as FLOATs AKA DOUBLEs

However, PHPs ip2long function returns a signed integer value, rather that the long value implied. This means that any IP address higher than 127.255.255.255 gets a negative value, which is incorrect.

The following function returns a properly formatted float.

function myip2long($ip){
    return floatval(sprintf("%u",ip2long('$ip')));
}


@Ben Faust

Your function returns the number as a string value, instead of a number, (not a big problem in PHP I know) but why do you pad the result out to 10 digits with 0's ?</description>
		<content:encoded><![CDATA[<p>@Ashley Sheridan</p>
<p>This is incorrect, a negative numbered IP number is simply an indication that the wrong datatype is being used to store it.<br />
IP Addresses are actually a 32bit binary number, in decimal these are values between 0 (0.0.0.0) and 4294967295 (255.255.255.255)</p>
<p>On 32Bit Computer Systems (i.e. most PCs &amp; servers out there today), an UNSIGNED integer value has the range 0-4294967295. A SIGNED Interger will have the range −2147483648 to +2147483647.  This is because 1 bit is &#034;Wasted&#034; as the sign.</p>
<p>However PHP (for reasons that are completely beyond me) doesn&#039;t support unsigned integers.  For this reason, IP numbers in PHP *should* be stored as FLOATs AKA DOUBLEs</p>
<p>However, PHPs ip2long function returns a signed integer value, rather that the long value implied. This means that any IP address higher than 127.255.255.255 gets a negative value, which is incorrect.</p>
<p>The following function returns a properly formatted float.</p>
<p>function myip2long($ip){<br />
    return floatval(sprintf(&#034;%u&#034;,ip2long(&#039;$ip&#039;)));<br />
}</p>
<p>@Ben Faust</p>
<p>Your function returns the number as a string value, instead of a number, (not a big problem in PHP I know) but why do you pad the result out to 10 digits with 0&#039;s ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randall Spychalla</title>
		<link>http://www.justin-cook.com/wp/2006/11/28/convert-an-ip-address-to-ip-number-with-php-asp-c-and-vbnet/#comment-146801</link>
		<dc:creator>Randall Spychalla</dc:creator>
		<pubDate>Tue, 16 Sep 2008 15:44:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.justin-cook.com/wp/2006/11/28/convert-an-ip-address-to-ip-number-with-php-asp-c-and-vbnet/#comment-146801</guid>
		<description>The Net call: System.Net.IPAddress.Parse(IPAddress).Address has been deprecated by Microsoft in VS 2008 due to being extremely buggy. It won't correctly handle quite a few addresses.</description>
		<content:encoded><![CDATA[<p>The Net call: System.Net.IPAddress.Parse(IPAddress).Address has been deprecated by Microsoft in VS 2008 due to being extremely buggy. It won&#039;t correctly handle quite a few addresses.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Faust</title>
		<link>http://www.justin-cook.com/wp/2006/11/28/convert-an-ip-address-to-ip-number-with-php-asp-c-and-vbnet/#comment-137106</link>
		<dc:creator>Ben Faust</dc:creator>
		<pubDate>Tue, 29 Jul 2008 21:40:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.justin-cook.com/wp/2006/11/28/convert-an-ip-address-to-ip-number-with-php-asp-c-and-vbnet/#comment-137106</guid>
		<description>In PHP, this can be done more simply, like this:

function ip_address_to_number( $IPAddress )
{ 
    return sprintf("%010u", ip2long( $IPAddress ) );
}</description>
		<content:encoded><![CDATA[<p>In PHP, this can be done more simply, like this:</p>
<p>function ip_address_to_number( $IPAddress )<br />
{<br />
    return sprintf(&#034;%010u&#034;, ip2long( $IPAddress ) );<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.137 seconds -->
