in reply to Why does it return 0?
is how I'd do it (untested). (The "%b" format was added in perl 5.6.0.) Don't forget to actually use the parameter you pass. Also, in your code $binnumb = $binnumb . $binary would be usually written $binnumb .= $binary. (Either is exempt from the usual warning that $binnumb is undefined; other operators special-cased this way are +, -, ||, &&, ^, |, ++, --.)sub dec2bin { my $inNumber = shift; my $sign = $inNumber=~s/^-// ? '-' : ''; return $sign.sprintf "%b", $inNumber; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Why does it return 0?
by mAineAc (Novice) on Feb 05, 2004 at 02:17 UTC | |
by ysth (Canon) on Feb 05, 2004 at 02:20 UTC | |
by mAineAc (Novice) on Feb 05, 2004 at 02:46 UTC | |
by ysth (Canon) on Feb 05, 2004 at 03:24 UTC |