I guess there's a much shorter way? Cheersuse warnings; use strict; print "Please input a decimal no. to convert to binary : "; chomp (my $value = <STDIN>); if ($value & 1) { print "1"; } else { print "0"; } if ($value & 2) { print "1"; } else { print "0"; } if ($value & 4) { print "1"; } else { print "0"; } if ($value & 8) { print "1"; } else { print "0"; } if ($value & 16) { print "1"; } else { print "0"; } if ($value & 32) { print "1"; } else { print "0"; } if ($value & 64) { print "1"; } else { print "0"; } if ($value & 128) { print "1"; } else { print "0"; }
In reply to Re^3: Bitwise operators
by thevoid
in thread Bitwise operators
by thevoid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |