|
Posted by Tim Roberts on 06/12/06 06:22
"Richard Levasseur" <richardlev@gmail.com> wrote:
>Perhaps the binary<->decimal functions would be of use:
>
>http://us3.php.net/manual/en/function.decbin.php
>http://us3.php.net/manual/en/function.bindec.php
>http://us3.php.net/manual/en/function.base-convert.php
No. All of those function are defined as accepting integers. PHP will
helpfully convert the floating value to int before performing the
conversion.
>Also, bitwise operators don't work on floating point numbers in PHP? I
>don't have access to PHP right now, but I find that odd.
No. The bitwise operators are ALSO defined as accepting integers.
PHP was just not designed for doing this kind of hackery. It makes it easy
to do the things that people really need to do.
On the other hand, C won't do this, either. This results in a compilation
error:
double d = 6.0;
return d & 0xffff0000;
And this does the same thing as PHP -- it converts to int first:
return (int)d & 0xffff0000;
You have to either use a union, or convert it as a pointer:
return (*(int*)&d) & 0xffff0000;
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
[Back to original message]
|