hi all..,

I have a question.

I am currently trying to learn perl with the book: beginning perl.

I have done the first chapter and im working on the exercises of the second chapter.

In the exercises i am expected to use things that are not explained.

chomp was the first one i had to use but is not explained.

INT is the second i had to use but is not explained.

And the bitwise & operator was explained but not enough to understand the usage of it when trying to convert decimal to binary

Here is my question:

This is the Ex2_3.plx solution code to my litlle decimal to binary conversion problem:
#!usr/bin/perl #Ex2_3.plx use warnings; print "Please enter the value(less than 256) you wish to be converted +into binary : \n"; my $bin = <STDIN>; chomp ($bin); print "The binary value of $bin is : ", "\n"; #Use the bitwise and operator to determine the binary value: print ((128&$bin)/128); print ((64&$bin)/64); print ((32&$bin)/32); print ((16&$bin)/16); print ((8&$bin)/8); print ((4&$bin)/4); print ((2&$bin)/2); print ((1&$bin)/1); print "\n";
I understand everything except this part:
print ((128&$bin)/128); print ((64&$bin)/64); print ((32&$bin)/32); print ((16&$bin)/16); print ((8&$bin)/8); print ((4&$bin)/4); print ((2&$bin)/2); print ((1&$bin)/1); print "\n";
In the book it is not explained how this works.. I know that it works but i just cant figure out how. Can someone please explain to me how this works? I like it if i can get something to work but i love it when i get something to work and know how it works.

Thx in advance

In reply to Bitwise and operator question by Severy

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.