Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Unpack a single byte from a binary string

Tags:

php

rawstring

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?

like image 935
tru7 Avatar asked Sep 17 '26 04:09

tru7


1 Answers

Ascii value:

$b=sha1($k,true);
echo ord($b[$ix]);
like image 186
LF00 Avatar answered Sep 19 '26 16:09

LF00



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!