H
hara
#!\c\perl\bin
print "Enter Bus no :";
chomp($bus = <STDIN>);
# convert bus no. to binary
system("cls");
@array;
$rem = 0;
while($bus>=2)
{
$rem = $bus % 2;
$bus = int($bus/2);
push(@array,$rem);
}
push(@array,$bus);
@bus = reverse(@array);
print "The binary representation of BUS ID is : @bus \n";
#here i want to convert the binary number into 8 bits by putting '0' on
the left.
$bus1=length("@bus");
print "$bus1\n";
if ($bus1==1)
{
@bus="0000000@bus";
}
elsif($bus1==2)
{
@bus="000000@bus";
}
elsif($bus1==3)
{
@bus="00000@bus";
}
else
{
@bus="0000@bus";
}
print "@bus\n";
But this is not working?
then i want to convert that 8 bits (by taking 4 bits at a time) to
decimal.
Can any body suggest anything?
how to count the length of the @bus variable.
and then add zeros on it's left?
print "Enter Bus no :";
chomp($bus = <STDIN>);
# convert bus no. to binary
system("cls");
@array;
$rem = 0;
while($bus>=2)
{
$rem = $bus % 2;
$bus = int($bus/2);
push(@array,$rem);
}
push(@array,$bus);
@bus = reverse(@array);
print "The binary representation of BUS ID is : @bus \n";
#here i want to convert the binary number into 8 bits by putting '0' on
the left.
$bus1=length("@bus");
print "$bus1\n";
if ($bus1==1)
{
@bus="0000000@bus";
}
elsif($bus1==2)
{
@bus="000000@bus";
}
elsif($bus1==3)
{
@bus="00000@bus";
}
else
{
@bus="0000@bus";
}
print "@bus\n";
But this is not working?
then i want to convert that 8 bits (by taking 4 bits at a time) to
decimal.
Can any body suggest anything?
how to count the length of the @bus variable.
and then add zeros on it's left?