I think that the answer to your question is easier than you think. $result is in the 0's and 1's format you desire already. The question, then, is how to manipulate that data!

Are you familiar with masks? If not, then you need to read more about binary math. If you are familiar with masks, then the following will be straightforward. Suppose you want to find out whether the value in the 4th position from the right is set and then do something like set the value in the second position from the right. The code to do this in PERL is below:

my $mask=1<<3; # Take 1 and shift it three positions left # The parens below are NECESSARY due to binding if (($result & $mask) == $mask) { my $new_mask=1<<1; $ Move 1 to the second position $result |= $new_mask; }

I hope this answers your question!


In reply to Re: Bytes to bits by bfish
in thread Bytes to bits by Gerard

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.