You are here: Re: & behaves differently « PHP Programming Language « IT news, forums, messages
Re: & behaves differently

Posted by d on 11/18/18 11:41

"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:6vCdnYaBloS7MZXZnZ2dnUVZ_vidnZ2d@comcast.com...
>d wrote:
>> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
>> news:P4qdnZ1ghuZKFJXZRVn-qw@comcast.com...
>>
>>>fritz-bayer@web.de wrote:
>>>
>>>>Hi,
>>>>
>>>>why does the php expression
>>>>
>>>>$result = 5543039447 & 2147483648;
>>>>
>>>>when executed evaluate to 0, whereas the perl expression
>>>>
>>>>$same = 5543039447 & 2147483648 ;
>>>>
>>>>evaluate to 2147483648 ???
>>>>
>>>>Fritz
>>>>
>>>
>>>Because Perl is using 64 bit integers and PHP is using 32 bit integers.
>>>
>>>2147483648 is not a valid value in 32 bit arithmetic. The largest value
>>>you can have is 2147483647.
>>
>>
>> PHP interprets ints over 32 bits as floats, so they are valid.
>>
>> "If you specify a number beyond the bounds of the integer type, it will
>> be interpreted as a float instead. Also, if you perform an operation that
>> results in a number beyond the bounds of the integer type, a float will
>> be returned instead."
>>
>>
>>>--
>>>==================
>>>Remove the "x" from my email address
>>>Jerry Stuckle
>>>JDS Computer Training Corp.
>>>jstucklex@attglobal.net
>>>==================
>>
>>
>>
>
> In most cases, yes. However, you cannot perform bit operations on a
> float. It must be an integer type.
>
> So the value is converted back to an integer, and since it's outside the
> bounds of a 32 bit integer the result is to strip off the high order bits.
>
> The result is zero.

The result is zero regardless of whether that bit is there or not :)

> Sometimes a little knowledge is worse than no knowledge at all.
>

Indeed.

> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация