tru7
tru7

Reputation: 7212

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?

Upvotes: 3

Views: 797

Answers (1)

LF-DevJourney
LF-DevJourney

Reputation: 28529

Ascii value:

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

Upvotes: 2

Related Questions