<?php var_dump(gmp_scan0("434234", -10)); var_dump(gmp_scan0("434234", 1)); var_dump(gmp_scan0(4096, 0)); var_dump(gmp_scan0("1000000000", 5)); var_dump(gmp_scan0("1000000000", 200)); $n = gmp_init("24234527465274"); var_dump(gmp_scan0($n, 10)); var_dump(gmp_scan0(array(), 200)); var_dump(gmp_scan0(array())); var_dump(gmp_scan0()); echo "Done\n";
echo gmp_strval($pow1) . "\n"; // gmp_prob_prime echo gmp_prob_prime("6") . "\n"; // definitely not a prime echo gmp_prob_prime("1111111111111111111") . "\n"; // probably a prime echo gmp_prob_prime("11") . "\n"; // definitely a prime // gmp_random -- not implemented // gmp_scan0 // "0" bit is found at position 3. index starts at 0 $s1 = gmp_init("10111", 2); echo gmp_scan0($s1, 0) . "\n"; // "0" bit is found at position 7. index starts at 5 $s2 = gmp_init("101110000", 2); echo gmp_scan0($s2, 5) . "\n"; // gmp_scan1 // "0" bit is found at position 3. index starts at 0 $s1 = gmp_init("01000", 2); echo gmp_scan1($s1, 0) . "\n"; // "0" bit is found at position 7. index starts at 5 $s2 = gmp_init("01000001111", 2); echo gmp_scan1($s2, 5) . "\n"; // gmp_setbit $a = gmp_init("2"); // echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n"; gmp_setbit($a, 0); // 0b10 now becomes 0b11 echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n"; $a = gmp_init("0xfd");
private function setIPv6( $addr, $mask ) { $this->net_addr = @inet_pton($addr); if( $this->net_addr == false ) { throw new Exception( "invalid ip address {$addr}" ); } $this->valid = true; $this->net_addr_long = $this->inet_ntogmp( $this->net_addr ); //$this->inet_gmpton( $this->net_addr_long ); // set the netmask if( preg_match( '/^[0-9]+$/', $mask )) { $this->net_mask_bits = intval( $mask ); if( $this->ipv4 && $this->net_mask_bits != 0 ){ $this->net_mask_bits += 96; } $this->net_mask_long = gmp_mul( gmp_sub( gmp_pow( 2, $this->net_mask_bits ), 1 ), gmp_pow( 2, 128-$this->net_mask_bits )); // echo gmp_strval( $this->net_mask_long, 2 )."<br />\n"; $this->net_mask = $this->inet_gmpton($this->net_mask_long); } else { $this->net_mask = inet_pton($mask); $this->net_mask_long = $this->inet_ntogmp($this->netmask); $this->net_mask_bits = gmp_scan0( $this->net_mask_long, 0 ); } // normalize it... $this->net_addr_long = gmp_and( $this->net_addr_long, $this->net_mask_long ); $this->net_addr = $this->inet_gmpton( $this->net_addr_long ); $this->net_broadcast_long = gmp_or( $this->net_addr_long, gmp_sub( gmp_pow( 2, 128-$this->net_mask_bits ), 1 )); $this->net_broadcast = $this->inet_gmpton($this->net_broadcast_long ); }