note 49417 added to language.types.integer

From: Date: Thu, 27 Jan 2005 09:15:43 +0000
Subject: note 49417 added to language.types.integer
Groups: php.notes 
Request: Send a blank email to php-notes+get-84059@lists.php.net to get a copy of this message
When doing large subtractions on 32 bit unsigned integers the result sometimes end up negative. My example script converts a IPv4 address represented as a 32 bit unsigned integer to a dotted quad (similar to ip2long()), and adds a "fix" to the operation. /************************** * int_oct($ip) * Convert INTeger rep of IP to octal (dotted quad) */ function int_oct($ip) { /* Set variable to float */ settype($ip, float); /* FIX for silly PHP integer syndrome */ $fix = 0; if($ip > 2147483647) $fix = 16777216; if(is_numeric($ip)) { return(sprintf("%u.%u.%u.%u", $ip / 16777216, (($ip % 16777216) + $fix) / 65536, (($ip % 65536) + $fix / 256) / 256, ($ip % 256) + $fix / 256 / 256 ) ); } else { return(''); } } ---- Manual Page -- http://www.php.net/manual/en/language.types.integer.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49417 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49417&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49417&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49417&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49417&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49417&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49417&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84059) next »