use strict; use warnings; # you can declare a nunber in many different formats. # see https://perldoc.perl.org/perlnumber.html # my $N1 = 0b11010111; my $N2 = 0b10110100; # or $N2 = 180; # or $N2 = 0xb4 # logical *bitwise=bit-by-bit* AND: (and not &&), btw OR is | my $N1_AND_N2 = $N1 & $N2; # you can print a number in many different formats # by default it prints in decimal print "Decimal notation: $N1 AND $N2 = $N1_AND_N2\n"; # but youn change the print format using printf (C-like): printf "Binary notation: %b AND %b = %b\n", $N1, $N2, $N1_AND_N2; printf "Hex notation: %x AND %x = %x\n", $N1, $N2, $N1_AND_N2;

bw, bliako


In reply to Re^3: Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl by bliako
in thread Bit manipulation of a bit stream to generate different elements of an array with each nibble taking either 0 or 1 in perl by spriyada29

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.