Best way to convert Little-Endian DWORD to string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Maybe quite strange question and quite off topic, but there's PHP involved :)

I want to read out files, and then I come across 4byte DWORD values,
they are stored in little endian values, but how do I get in a PHP
string (as the values are too large for integer)

My code is currently this:
$data = fread($fp,4);
$value = (ord(substr($data,3,1))*256*256*256)+(ord(substr($data,2,1))*256*256)+(ord(substr($data,1,1))*256)+(ord(substr($data,0,1)));

and now $value contains the value of the DWORD, it works fine, but it
seems that it could be done a lot easier :)
Anyone experience with it?

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux