You are here: Re: Binary manipulation of a floating point number « PHP Programming Language « IT news, forums, messages
Re: Binary manipulation of a floating point number

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.

 

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

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