Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare hex variable to certain value

Status
Not open for further replies.

EfratS

MIS
Aug 4, 2004
15
CA
Hello,

I'm trying to run the following code:
$found = 0;
$posCount = 0;
while (!($found)){
$b = substr($callBuf, $posCount, 24);
$data = unpack('H24',$b);
if ($data == "0000001d0000000700000001"){
$found = 1;
}
else{
++$posCount;
}
}

$callBuf contains binary data that were read from file,
and the code above suppose to find the position of "0000001d0000000700000001" in $callBuf.
if I print the $data variable I can see that in certain iteration it holds the needed value, but from some reason the comparison statement doesn't "catch" it!
 
As far as I can tell, you're only actually comparing strings, so there's no need for the unpack. Just compare $b (which should really be called something else, incidentally, since it's a special variable for use in the sort() function) to your binary string, using `eq', as duncdude suggested.
 
I reckon ish is right - what is the string before you unpack it?


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top