Search code examples
phprawstring

PHP Unpack a single byte from a binary string


I have a raw string of bytes $b coming from

$b=sha1($k,true);

I need to know the value of $b[$ix]. The only way I've found is

$arr=unpack('Cw',$b[$ix]);
$value=$arr["w"];

But for such elemental operation it seems too much overload.

Is there a more straight way to access the bytes in a raw string?


Solution

  • Ascii value:

    $b=sha1($k,true);
    echo ord($b[$ix]);