develooper Front page | perl.fwp | Postings from November 2011

decimal -> Binary

Thread Next
From:
Sandro CAZZANIGA
Date:
November 16, 2011 05:26
Subject:
decimal -> Binary
Message ID:
CAFLWM9TCatgTZv-3jrBZgDm88ZRLu7aFg2oCHbkXzUsn_jPA8w@mail.gmail.com
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;

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About