Page 1 of 1

Problems Reading file at a Byte level

Posted: Thu Dec 01, 2005 5:40 pm
by clem_c_rock
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hello,

I am reading a file and trying to decifer individual bytes in a shockwave file and having a great deal of success. I'm having problems decoding an example.

The file is a compressed file and I can read most of the header information w/ no problem.

I encounter a bit of difficulty w/ this line of code:

Code: Select all

$buffer = fread($fp, $this->size ) ;
$buffer = gzuncompress($buffer, $this->size);

$this->fps = Array() ;

for( $i=0; $i<2; $i++ )
{
$t = substr($buffer,0,1 ); #take the first byte in front
$t = ord($t) ;
$buffer = substr($buffer,1) ;
$this->fps[] = $t ;
}
the out put for the $this->fps[1] is 12 and the output for $this->fps[0] is 0;

the hex dump for the 2 bytes are: C0 C0

I know the bytes are being swapped somehow but I do not really understand how.

Any ideas?


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Dec 01, 2005 7:40 pm
by josh
big endian and little endian?

Edit: you should actually be using http://us2.php.net/unpack to read the binary data