Problems Reading file at a Byte level

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clem_c_rock
Forum Commoner
Posts: 46
Joined: Mon Jun 07, 2004 9:18 am

Problems Reading file at a Byte level

Post 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]
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

big endian and little endian?

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