You are here: Binary Data: Single Bits « All PHP « IT news, forums, messages
Binary Data: Single Bits

Posted by Mathias K. on 03/11/07 16:52

Hello everyone!

I'm currently dealing a lot with binary data.
Therefore it is sometimes that i have to read or write
single bits. What is the best way to do that?

For example let it be one single byte where the first 5 bits
contain a certain information, and the rest belongs to the next
binary block.

Now i get those 5 bits as follows: <<<PHP

// $fp is a filepointer to an open binary file

$byte = fread($fp, 1); // one byte
$bin = decbin( ord( $byte ) );

$fivebits = bindec( substr($byte, 0, 5) );

PHP;

Well that seems kind of long winded to me.
Isn't there are better, quicker and more elegant way to do that in PHP?
Because right now i don't know of any.


Thanks for any hints in advance.

~ MK

 

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

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