0

Is there a clever way to convert bytes in array into PHP-int.

//data holding three int32's
$data = array(0,53,100,200,0,0,0,0,10,20,30,40);
$myInt1 = cleverWay($data,0,'big-endian'); //0 = startpoint to parse

//myInt1 should now contain 0 + 53 * 2^8 + 100 * 2^16 + 200 * 2^24
//(there's a glitch here since int32 probably is signed and
//comment above uint32.
7
  • 1
    What's the expected output? I'm a bit confused about the 12 values and "three int32" comment. Commented Apr 22, 2016 at 14:25
  • Are you asking to sum the ints in the array to one int? Commented Apr 22, 2016 at 14:25
  • Are you learning or copy-pasting code from somewhere ... ? Commented Apr 22, 2016 at 14:30
  • 1
    (0 << 24) + (53 << 16) + (100 << 8) + 200, basically. Commented Apr 22, 2016 at 14:30
  • 1
    for reading unit32 from strings take a look at: stackoverflow.com/a/17963326/5378743 Commented Apr 22, 2016 at 14:38

0

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.