To see your program as Perl sees it, deparse it:
See O and B::Deparse.c:\@Work\Perl\monks>perl -wMstrict -MO=Deparse,-p -e "print 'Enter decimal number less than 256: '; my $decimal; $decimal=<STDIN>; chomp $decimal; print $decimal & 128 <=> 0; print $decimal & 64 <=> 0; print $decimal & 32 <=> 0; print $decimal & 16 <=> 0; print $decimal & 8 <=> 0; print $decimal & 4 <=> 0; print $decimal & 2 <=> 0; print $decimal & 1 <=> 0; " BEGIN { $^W = 1; } use strict 'refs'; print('Enter decimal number less than 256: '); my($decimal); ($decimal = <STDIN>); chomp($decimal); print(($decimal & 1)); print(($decimal & 1)); print(($decimal & 1)); print(($decimal & 1)); print(($decimal & 1)); print(($decimal & 1)); print(($decimal & 1)); print(($decimal & 1)); -e syntax OK
Update: Why does every expression like 128 <=> 0 become the constant 1? Because the Perl compiler, like most compilers today, is smart enough to know that the result of the comparison of a constant to a constant is just going to be yet another constant, 1 in all these cases. (Update: I believe this process is called constant folding.)
Give a man a fish: <%-(-(-(-<
In reply to Re: decimal to binary conversion
by AnomalousMonk
in thread decimal to binary conversion
by mp0065789
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |