w*s 发帖数: 7227 | 1 i read 4 bytes from a file,
say it's 88130000 in the hex format,
now i want to pack it to 0x00001388 which is 5000 dex.
so basically how to convert 0x88130000 into 5000 (0x00001388).
my code is like this, way to complicated.
$bytes = read($fh, $buf, 4);
$word = unpack 'H*', $buf;
print $word."\n";
($d2,$d3,$d0,$d1) = unpack("b8 b8 b8 b8", $word);
$newWord = pack("b8 b8 b8 b8", $d0,$d1,$d2,$d3);
print $newWord."\n";
print hex($newWord)."\n";
any suggestions ? | w****w 发帖数: 521 | 2 use v to unpack to little endian. |
|