small intToNum fix
[PHP-P10.git] / Uplink / Numerics.class.php
index 55db20977a6b0ecc3042f3def2753f4a984bb0b0..943fc15ee365a6e6ba8192b1d8c0f87a7e3df426 100644 (file)
  *
  * static int numToInt(String $numeric)
  *     returns the integer value, the numeric represents
+ *
+ * static String parseIP(String $numeric)
+ *     parses an IP Address in numeric format
+ *
+ * static String numericFromIP(String $ip)
+ *     builds a numeric representing the IP
  */
 
 class Numerics {
@@ -44,9 +50,6 @@ class Numerics {
        private static $base64charsLength = 64;
        
        public static function intToNum($int, $length) {
-               //fix a small "bug": normaly 0 = AAAAA but we need 1 = AAAAA
-               $int = $int - 1;
-               
                $numeric = "";
                for($pos = $length-1; $pos >= 0; $pos--) {
                        //current position represents floor($int / ($base64charsLength ^ $pos))
@@ -55,6 +58,7 @@ class Numerics {
                                $base = $base * self::$base64charsLength;
                        }
                        $posValue = floor($int / $base);
+                       $int -= $posValue * $base;
                        //get the char representing $posValue
                        $posChar = self::$base64chars[$posValue];
                        $numeric .= $posChar;
@@ -71,10 +75,6 @@ class Numerics {
                        $int = ($posValue * $base);
                        $base = $base * self::$base64charsLength;
                }
-               
-               //fix a small "bug": normaly 0 = AAAAA but we need 1 = AAAAA
-               $int = $int + 1;
-               
                return $int;
        }