in reply to Re: How do I convert between decimal and binary?
in thread How do I convert between decimal and binary?

#or, in v5.6.0 sub dec2bin {return sprintf "%b",shift } #and sub bin2dec{ return oct"0b$_[0]"}

Replies are listed 'Best First'.
Re^2: Answer: How do I convert between decimal and binary?
by Anonymous Monk on Apr 05, 2013 at 04:42 UTC
    #!/user/local/bin/perl print "\nEnter the num:"; @rem=(); $dec =<STDIN>; print "converting to binary"; while ($dec> 0) { @rem$i++ = $dec % 2; $dec= int ($dec/2); } print reverse(@rem);
Re^2: Answer: How do I convert between decimal and binary?
by Anonymous Monk on Sep 11, 2004 at 14:31 UTC
    I have 32 bits, that I need to convert to decimal. This seems to be a problem for bin2doc. Do I encounter an overflow?
      Shouldn't be a problem; what version of perl are you using? 0b is only supported as of 5.6.0.