Saturday, May 31, 2014

How to run a program in Perl

pqr47.us.company.com: / >
pqr47.us.company.com: / >
pqr47.us.company.com: / > cat binary-to-decimal
#!/usr/bin/perl

print ("Enter a Binary number: ");
$bina_number = <STDIN>;
chop ($bina_number);

$decimal = oct("0b".$bina_number);

print ("The decimal equivalent of the Binary number $bina_number is:  ", $decimal);
print ("\n");

pqr47.us.company.com: / >
pqr47.us.company.com: / >
pqr47.us.company.com: / >
pqr47.us.company.com: / > ./binary-to-decimal
Enter a Binary number: 1010110101110001101010
The decimal equivalent of the Binary number 1010110101110001101010 is:  2841706
pqr47.us.company.com: / >
pqr47.us.company.com: / >

No comments:

Post a Comment