Re: [PHP4BETA] bugs and a leak

From: Date: Thu, 13 Apr 2000 21:02:51 +0000
Subject: Re: [PHP4BETA] bugs and a leak
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-13533@lists.php.net to get a copy of this message
> Okay, so I've got this partially figure out but I'm wondering if there's a > better way. So fread returns a binary string, what's the best way to do a > comparison on this? For my case here i can do an ord() on $one and $two > thus making it an integer and the & and comparison then work. But what > about for a larger value? Would I have to loop through and call ord() on > each byte? Now you are getting endianess. How do you know you have a larger value. If the first two bytes of your file are 0xff and 0xf0, how do you you whether these bytes represent two distinct 8-bit numbers or a single 16-bit number? And if it is a 16-bit number, is it stored with its most significant byte first or last? So, you need to know the byte-ordering of the file and you need to know the structure of the file. In order to reconstruct a 16-bit number you would do something like: $byte1 = ord(fread($fp,1)); $byte2 = ord(fread($fp,1)); $value = 256*$byte1 + $byte2; -Rasmus

« previous php.version4 (#13533) next »