TeamViterbi has asked for the wisdom of the Perl Monks concerning the following question:
Basically, I'm trying to read a binary file 32 bits at a time by unpacking them into decimal and then adding them. Furthermore, I am trying to use the $checksum & 0xFFFFFFFFF command to restrain the checksum to 32 bits. Also, just ignore the commented out stuff, I was using it for my own testing. Any assistance would be greatly appreciated.Code: #!/usr/bin/perl -w use strict; use FileHandle; use warnings; my $data = "file.bin"; my $buffer; my $string; my $n = 0; my $checksum = 0; my $num = 0; my $str = unpack("B32", pack("N", shift)); my $bits = 4; my $decimal; open FILE, $data or die $!; binmode FILE; while (($n = read FILE, $buffer, 4)) { $decimal = unpack("N", pack("B32", $buffer)); {$checksum = $checksum + $decimal; #$num = $num + $bits;} #print "1. $num\n"; print "2. $decimal\n"; #print "3. $n bytes read\n"; print "4. $checksum \n"; } $checksum = $checksum & 0xFFFFFFFF;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Difficulty restraining read function to 32 bits
by ikegami (Patriarch) on Jul 15, 2009 at 23:24 UTC | |
by TeamViterbi (Novice) on Jul 15, 2009 at 23:48 UTC | |
by ikegami (Patriarch) on Jul 16, 2009 at 14:44 UTC | |
|
Re: Difficulty restraining read function to 32 bits
by jwkrahn (Abbot) on Jul 16, 2009 at 00:05 UTC |