Re: Failure in bitwise operations moving from 5.2.x to 5.3.x
| From: | Joel | Date: | Tue, 15 Mar 2011 16:38:14 +0000 |
| Subject: | Re: Failure in bitwise operations moving from 5.2.x to 5.3.x | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311876@lists.php.net to get a copy of this message | ||
You might want to take a look at the BC Math functions, which can
perform operations on arbitrary length numbers.
On Tue, Mar 15, 2011 at 12:31 PM, Ford, Mike <M.Ford@leedsmet.ac.uk> wrote:
>> -----Original Message-----
>> From: Andy McKenzie [mailto:amckenzie4@gmail.com]
>> Sent: 15 March 2011 15:51
>>
>> As it turns out, the most important lesson here is: "Don't trust
>> what
>> anyone tells you." The old server is 64-bit. The new server is
>> 32-bit. Once I stopped to check that myself, it all became clear.
>> For the archives, here's what happened.
>>
>> Everything worked fine until I ran bindec() on the binary netmask;
>> at
>> that point it returned a float rather than an int, as it it used to.
>> Therefore, when I ran ip2long on the result, it choked, and returned
>> bool(false). Which isn't really useful when you're trying to
>> produce
>> a human-readable netmask, when you get right down to it.
>>
>> I still don't have a solution that will work on a 32-bit server, but
>> now that I know what's going on, I should be able to either find
>> something that will work, or get things moved to a 64-bit machine.
>
> You may have to use a replacement for bindec which employs bit-shifting
> to get the result you want; something like:
>
> function my_bindec($binstr)
> {
> $binlen = strlen($binstr);
> $decval = 0;
> for ($i=0; $i<$binlen; ++$i):
> $decval = ($decval<<1) | ($binstr[$i]?1:0);
> endfor;
>
> return $decval;
> }
>
> Note: off the top of my head and completely UNTESTED!
>
> Also, the constant 4294967295 quoted in your original message will
> become a float value on a 32-bit system. It's actually a representation
> of 32-bit -1, so either write it like that or use something like
> ip2long('255.255.255.255') (or
> my_bindec('11111111111111111111111111111111')!!!).
>
>
> Cheers!
>
> Mike
>
> --
> Mike Ford,
> Electronic Information Developer, Libraries and Learning Innovation,
> Leeds Metropolitan University, C507 City Campus,
> Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom
> Email: m.ford@leedsmet.ac.uk
> Tel: +44 113 812 4730
>
>
>
>
> To view the terms under which this email is distributed, please go to
> http://disclaimer.leedsmet.ac.uk/email.htm
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>