Php convert byte string to integer

I'm trying to convert a 2 byte string to Short / int datatype with unboxing, but it doesn't work:

$str = "\x01\xBB";
unpack("S",$str);

      

it gives 47873 where it should return 443

+3


source to share


1 answer


Instead, it should be used n

as a format string.

$str = "\x01\xBB";
unpack("n",$str);

      



Take a look here for more format options.
http://php.net/manual/en/function.pack.php

+4


source







All Articles