[SLUG] PHP Question: strings and numbers

From: Paul M Foster (paulf@quillandmouse.com)
Date: Thu Aug 25 2005 - 23:32:13 EDT


Anyone know how to pull data out of a file and interpret it as binary in
PHP? Specifically, I have four bytes in a file whose contents I want to
bit-shift left by varying amounts, and then store the results as a
number. The raw data is binary. In python, it looks like this:

s0 = ord(four_byte_string[0])
s1 = ord(four_byte_string[1])
s2 = ord(four_byte_string[2])
s3 = ord(four_byte_string[3])
return (s3 << 24) | (s2 << 16) | (s1 << 8) | s0

and the value returned should be a number. Anyone know how to accomplish
a similar thing in PHP?

-- 
Paul M. Foster
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:32:50 EDT