0

I get the below binary value in php by collecting the value from a DB.

0xF4010800000000960106000000002f03040000000063030700000000...

The problem is i don't know how to read it in sections.

For example, the first part F401 should be returned as a smallint (2 bytes) 500 and then just after that 08000000 should be returned as an int (4 bytes unsigned) and return as 8, how is this done in PHP?

EDIT:

I have tried hexdec(substr($value, 0, 4)) to try and get the value 500. bit on the first 4 bytes but this dosen't work, i don't know what else to try.

2
  • 1
    Wel what have you tried so far? Commented Nov 27, 2015 at 15:06
  • $hex = bin2ex($binary); and $dec = hex2dec($dec); Commented Nov 27, 2015 at 15:11

1 Answer 1

1

https://www.php.net/manual/en/function.unpack.php

Note: Your data is packed in little-endian.

$bin = hex2bin('F4010800000000960106000000002f03040000000063030700000000');
var_dump(unpack('vone/itwo/h*remain', $bin));

Output:

array(3) {
  ["one"]=>
  int(500)
  ["two"]=>
  int(8)
  ["remain"]=>
  string(44) "0069106000000000f230400000000036307000000000"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.