Program No.8.B
Write a Perl script to convert the decimal number to binary number
Solution:
print"Enter a number to convert : ";
$num=<STDIN>;
$intnum=sprintf("%d",$num);
$i=0;
while($intnum>0)
{
$array[$i]=$intnum%2;
$intnum=int($intnum/2);
$i=$i+1;
}
print "Binary value : ";
for($j=$i;$j>=0;$j--)
{
print "$array[$j]";
}
Write a Perl script to convert the decimal number to binary number
Solution:
print"Enter a number to convert : ";
$num=<STDIN>;
$intnum=sprintf("%d",$num);
$i=0;
while($intnum>0)
{
$array[$i]=$intnum%2;
$intnum=int($intnum/2);
$i=$i+1;
}
print "Binary value : ";
for($j=$i;$j>=0;$j--)
{
print "$array[$j]";
}
0 comments:
Post a Comment