--8323328-1689967568-1121692797823 Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1689967568-1121692797=:7823" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-1689967568-1121692797823 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Mon, 18 Jul 2005, Dan Fitzpatrick wrote: > I am trying to port the OLE Reader from PHP to read Excel files on any > platform. I am stuck on the following function: > > function GetInt4d($data, $pos) { > return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | \ > (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24); > } > > My ruby version is: > > def get_int_4_d(data, pos) > (data[pos]) | ((data[pos+1]) << 8) | \ > ((data[pos+2]) << 16) | ((data[pos+3]) << 24) > end > > It works in some cases but in the example xls file I am using, when > data[pos,0] is the character the function returns -2 in PHP and 4294967294 > in Ruby. > > Thanks for your help. your php function should have been named GetSignedInt and your ruby function should be named get_unsigned_int_4_d remember, 2 ** 32 => 4294967296. for larger numbers your php function wraps and yields negative numbers - dunno if it's supposed to. you should look at String#unpack. assuming you want to unpack a signed int in lsb order from data starting at pos your method would become def get_int_4_d(data, pos) data[pos,4].unpack('i').first end although you should be sure to understand little/big endian issues with regard to your data and these functions. hth. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso =============================================================================== --8323328-1689967568-1121692797823-- --8323328-1689967568-1121692797823--