in reply to please explain this script
The program calculates a checksum, it does so by iterating over each character of the file ($/ = \1; while (<>)). It keeps a running, 32 bit checksum, initially zero. For each character, it will rotate the current checksum one bit leftward (note that it's rotating, not shifting). This is the ($c << 1) + ($c >> 31) part. Then for each fourth character, the code point number will be added to the running total. ($x >> 2 == 3 ? 0: ord); $x ++). Finally, the checksum is printed as a hex number.$/=\1;while(<>){$c=($c<<1)+($c>>31)+($.>>2==3?0:ord)}printf"%x",$c
Note that it will display different sums depending whether you have a 32-bit or a 64-bit perl!
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: please explain this script
by El Linko (Beadle) on May 28, 2004 at 13:54 UTC | |
by arcnon (Monk) on May 28, 2004 at 15:25 UTC | |
|
Re: Re: please explain this script
by arcnon (Monk) on May 28, 2004 at 15:32 UTC | |
by davido (Cardinal) on May 28, 2004 at 15:45 UTC |