Sure thing, here's a program that shows basically how I use the function.
@ItemList = (); #this would be filled with some data already, and pass +ed in as a reference. $ItemListRef = \@ItemList; $LCSStatWd1 = 524288; #this would normally come from the file $LCSStatWd1Bits = unpack("B32",pack("N",$LCSStatWd1)); #creating the b +it string print "$LCSStatWd1Bits\n"; #Discretes $Offset = 0; $LidarPwrState = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $LidarPwrStateToggle = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRe +f); $LCSMode = ReadBits($LCSStatWd1Bits,\$Offset,6,$ItemListRef); $LidarCondition = ReadBits($LCSStatWd1Bits,\$Offset,3,$ItemListRef); $NewCentAvail = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $ObjOutOfScnWin = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $ReAcqFailed = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $LaserState = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $GrCommEnable = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $LidarMode = ReadBits($LCSStatWd1Bits,\$Offset,2,$ItemListRef); $LCSSubMode = ReadBits($LCSStatWd1Bits,\$Offset,3,$ItemListRef); $GNCpredit = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $FOVedgemAz = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $FOVedgepAz = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $FOVedgemEl = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $FOVedgepEl = ReadBits($LCSStatWd1Bits,\$Offset,1,$ItemListRef); $Spare2 = ReadBits($LCSStatWd1Bits,\$Offset,6,$ItemListRef); sub ReadBits { my $BitStringIn = @_[0]; my $OffsetRef = @_[1]; my $Length = @_[2]; my $ItemListRef = @_[3]; my $BitStringOut = 0; $BitStringOut = substr($BitStringIn,$$OffsetRef,$Length); $$OffsetRef += $Length; $NumZeros = 32-$Length; $Zeros = unpack("B$NumZeros",pack("N",0)); $BitStringOut = $Zeros.$BitStringOut; $NumOut = unpack("N",pack("B32",$BitStringOut)); @$ItemListRef = (@$ItemListRef,$NumOut, "\t"); print "\n$NumOut"; return($NumOut); }
I did look at vec, however it didn't look like it would work for me since I sometimes read 3 or 6 bits. I'll try taking out the padding, I thought that each number would need to be the same length to do the conversion right.

In reply to Re^2: Reading individual bits by iKnowNothing
in thread Reading individual bits by iKnowNothing

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.