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 number $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); }