Severy has asked for the wisdom of the Perl Monks concerning the following question:
I understand everything except this part:#!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";
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 advanceprint ((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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bitwise and operator question
by FunkyMonk (Bishop) on Aug 09, 2007 at 14:13 UTC | |
by citromatik (Curate) on Aug 09, 2007 at 14:48 UTC | |
by Severy (Initiate) on Aug 09, 2007 at 15:26 UTC | |
by Severy (Initiate) on Aug 09, 2007 at 14:46 UTC | |
by FunkyMonk (Bishop) on Aug 09, 2007 at 14:55 UTC | |
by mr_mischief (Monsignor) on Aug 09, 2007 at 15:12 UTC | |
|
Re: Bitwise and operator question
by perrin (Chancellor) on Aug 09, 2007 at 14:13 UTC | |
|
Re: Bitwise and operator question
by johnlawrence (Monk) on Aug 09, 2007 at 15:04 UTC | |
|
Re: Bitwise and operator question
by ikegami (Patriarch) on Aug 09, 2007 at 14:47 UTC |