Re: BigEndian to integer

From: Date: Mon, 14 Jul 2003 16:46:35 +0000
Subject: Re: BigEndian to integer
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-155118@lists.php.net to get a copy of this message
Marek Kilimajer wrote: http://www.php.net/pack
A little background on what Im doing. Im attempting to read realaudio files for their metadata, so Im reading from a binary string, and Im currently using unpack() (Im new to using this function, so I may be wrong with its usage) to unpack the data, along with ord(), and the result is something like what I posted before -> 0 0 0 18 (I put the spaces in there so we know that each number is a byte) So Im not exactly sure how the pack() function would play a role in this. David Nicholson wrote:
Never heard of a BigEndian number beofre, but this should do it... function BigEndiantoInt($bigendian){ $bits = split(" ",$bigendian); $bits = array_reverse($bits); $value = 0; $columnvalue = 1; foreach($bits as $thisbit){
       $value = $value + ($columnvalue * $thisbit);
       $columnvalue = $columnvalue * 2;    }
return $value; }
For taste of what BigEndian or its counterpart LittleEndian is about, look at -> http://www.webopedia.com/TERM/B/big_endian.html http://whatis.techtarget.com/definition/0,,sid9_gci211659,00.html I'll give your function a shot, and see if I can get something meaningful from it. Thanks.

« previous php.general (#155118) next »