Re: Best way to convert Little-Endian DWORD to string
| From: | Tijnema | Date: | Wed, 30 May 2007 16:11:03 +0000 |
| Subject: | Re: Best way to convert Little-Endian DWORD to string | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-255818@lists.php.net to get a copy of this message | ||
On 5/30/07, Edward Kay <edward@labhut.com> wrote:
-----Original Message----- From: Tijnema [mailto:tijnema@gmail.com] Sent: 30 May 2007 15:20 To: php Subject: [PHP] Best way to convert Little-Endian DWORD to string 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*2 56)+(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? Could you not use the << bitwise operator? EdwardHow could I use them here? I read the docs for bitwise operators, and they tell me what they do, but now how to use it :( Tijnema