decimal -> Binary
Sandro CAZZANIGA <[email protected]> Wed, 16 Nov 2011 14:26:39 +0100
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <CAFLWM9TCatgTZv-3jrBZgDm88ZRLu7aFg2oCHbkXzUsn_jPA8w@mail.gmail.com> |
--20cf3074b732cfc7ae04b1da0d0c
Content-Type: text/plain; charset=ISO-8859-1
hi!
Just a little JAPH for convert decimal to binary.... Feel free to comment
it ;)
----------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
eval {@ARGV} or die("No args") ;
foreach my $arg(@ARGV) {
my $convert = unpack("B*",pack("N", $arg));
my @convertsp = split("", $convert);
my $count = 0;
foreach (@convertsp) {
unless ($convertsp[$count] == 1) {
$convertsp[$count] = "" ;
$count++;
}
}
print("$arg: @convertsp \n");
}
exit 0;
--20cf3074b732cfc7ae04b1da0d0c--