in reply to Re: decimal to binary conversion need help
in thread decimal to binary conversion need help

thank you but i need a perl code thank u
  • Comment on Re^2: decimal to binary conversion need help

Replies are listed 'Best First'.
Re^3: decimal to binary conversion need help
by ambrus (Abbot) on Jan 06, 2005 at 12:33 UTC

    Well, let's use a language with better bigint support. Yes, I know about Math::BigInt, but others will tell you about that anyway, so I'll show other solutions. For these, you have to install respective software (dc, bc, ruby) if you don't already have it.

    perl -we '"38"=~/(-?)(\d+)/ and $decimal = ($1?"_":"").$2; `dc -e 2o${ +decimal}p` =~ /(-?[01]+)/ and $binary = $1; print $binary, "\n";' perl -we '"9007199254740991"=~/(-?\d+)/ and $decimal = $1; `echo obase +=2\\;${decimal} | bc` =~ /(-?[01]+)/ and $binary = $1; print $binary, + "\n";' perl -we '"9007199254740991"=~/(-?\d+)/ and $decimal = $1; `ruby -e\47 +printf(%[%b],\$*[0])\47 ${decimal}` =~ /(-?[01]+)/ and $binary = $1; +print $binary, "\n";'