Re: Byte conversion
| From: | Tijnema | Date: | Mon, 25 Jun 2007 20:31:01 +0000 |
| Subject: | Re: Byte conversion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257758@lists.php.net to get a copy of this message | ||
On 6/25/07, Eric Butera <eric.butera@gmail.com> wrote:
I've been trying to figure out a way to do this all day and I'm afraid
I might need a bit of help. Basically I am trying to port over
something from Java to PHP and I'm stuck on one particular piece of
code:
if ((ba[i + 0] == (byte)0xa7) && (ba[i + 1] == (byte)0x51)) {
The code is looping through a byte array and checking if the current
value matches "(byte)0xa7", etc. If there is a match, then it breaks
and returns the value of i. There are quite a few more values than
this in the conditional, but I figure this is enough to get the point
across. My problem is I'm not exactly sure what the value of
(byte)0xa7 is.
I tried
$buffer = file_get_contents('Dining_Room.rti');
$count = strlen($buffer);
for ($x=0; $x < $count; $x++) {
$char = substr($buffer, $x, 1);
echo $char;
if ($char == 0xa7 && $char == 0x51) {
return $x;
}
}
but it never matches. Any pointers?
$char contains a token at the point, and you can't compare that with a
hex value AFAIK.
You could use ord[1] to get the ASCII value of $char, and compare it
with the decimal value of 0xA7(167) and 0x51(81).
Tijnema
[1] http://www.php.net/ord
--
Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info