php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #14668 wrong bit arithmetics
Submitted: 2001-12-23 06:55 UTC Modified: 2002-08-14 14:21 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: soletan at toxa dot de Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.1.0 OS: SuSE Linux 7.1
Private report: No CVE-ID: None
 [2001-12-23 06:55 UTC] soletan at toxa dot de
Hi,

using ip2long is strange enough itself (would you please 
do some better description on what I get out after calling 
this function or at least do some references to documents 
(RFCs) describing that "IP address in full length 
notation" format).

Anyhow: I'm coding the following

<?php
$a = base_convert( 0xFFFFFFFF ^ 1, 10 2 );
var_dump( $a );
?>

and get

string(2) "10"

(under 4.0.6 I got something different: 31 (!!!!) 1's in 
string without that trailing 0)

what about all the other leading bits that should be 1?



And in relation with the ip2long-trouble I'm having:

<?php
$a = base_convert( ip2long( "255.255.0.255" ), 10, 2 );
$b = base_convert( ip2long( "255.255.0.255" ) ^ 
0xFFFFFFFF, 10, 2 );

var_dump( $a, $b );

?>

what gives me

string(16) "1111111100000001" string(16) "1111111100000000"



I beg to get some fast response! This behaviour of ip2long 
and/or xor-operator is too strange to be easily understood 
after reading that minimal function reference entry. But I 
need it a lot for some work that needs to be done 
urgently!!

Thank you very much!


Regards,
Thomas Urban


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-04 00:13 UTC] yohgaki@php.net
Don't use ip2long/long2ip. It just dosen't work. 
Do it by yourself with bcmath.

Manual page should clearly note the limitation.
Changed to doc problem to see if manual is ok.


 [2002-08-14 14:21 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You are using ip2long, which in many cases will return a interger value greater then 2147483647 (on 32 bit machines). Since, PHP normally treats numbers as signed, numbers greater then 2147483647 become negative. The solution to your problem would be to use 
sprintf("%u", base_convert(ip2long("255.255.0.255" ) ^ 
0xFFFFFFFF, 10, 2 ));
This will tell php to treat the number as an unsigned integer, allowing it to go as high as 4294967295, which is largest value ip2long can possibly return.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 13:01:30 2024 UTC