iKnowNothing has asked for the wisdom of the Perl Monks concerning the following question:
sub ReadBits { my $BitStringIn = @_[0]; my $OffsetRef = @_[1]; my $Length = @_[2]; my $ItemListRef = @_[3]; my $BitStringOut = 0; #capture the relevant bits $BitStringOut = substr($BitStringIn,$$OffsetRef,$Length); #update Offset $$OffsetRef += $Length; #determine the number of zero's I need to add to make a 32-bit num +ber $NumZeros = 32-$Length; #Create string of zeros with a length of $NumZeros $Zeros = unpack("B$NumZeros",pack("N",0)); #Insert string of zeros to $BitString to create a 32-bit string $BitStringOut = $Zeros.$BitStringOut; #Convert 32-bit string into a number $NumOut = unpack("N",pack("B32",$BitStringOut)); #Update ItemList @$ItemListRef = (@$ItemListRef,$NumOut); return($NumOut); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading individual bits
by BrowserUk (Patriarch) on Jul 29, 2004 at 22:45 UTC | |
by iKnowNothing (Scribe) on Jul 29, 2004 at 23:26 UTC | |
by BrowserUk (Patriarch) on Jul 30, 2004 at 00:52 UTC | |
by BrowserUk (Patriarch) on Jul 30, 2004 at 01:17 UTC | |
by Anonymous Monk on Jul 30, 2004 at 13:41 UTC | |
|
Re: Reading individual bits
by jmcnamara (Monsignor) on Jul 29, 2004 at 23:59 UTC | |
|
Re: Reading individual bits
by Anonymous Monk on Aug 01, 2004 at 09:14 UTC |