I need clarification on a problem that I have. I am currently trying to learn Perl using the Beginning Perl book provided by the "Learn Perl" portion of the Perl website. I am down to the ending of chapter 2 and I am currently having a hard time trying to understand the logic behind a solution that the book provided.
#!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 can't seem to understand the logic behind (128 & n) / 128 and so forth. While I do understand why is it that the code needs to go from 128 down to 1 I can't seem to grasp the solution after &. I feel bad because I normally hate looking at solutions, but this is all very intriguing to me, most other programming books put very small(if any) attention to bitwise operators. I will appreciate the help.