![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl script variable to read shell command | bulkbiz | Shell Programming and Scripting | 4 | 10-10-2008 03:05 AM |
| Problems while read a file | lestat_ecuador | Shell Programming and Scripting | 7 | 06-23-2008 04:09 PM |
| Changing 24 bits to 8 bits display | larry | UNIX for Dummies Questions & Answers | 4 | 03-05-2002 11:51 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Problems restraining read command to 32 bits -perl
Hey everybody, I'm having difficulty using the read command to perform a checksum operation. Whenever I print the final checksum, the result always returns FFFFFFFF, and I know thats not the checksum. 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;
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. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|