in reply to decimal to binary conversion need help

9007199254740991 == 253-1 so it's 11111111111111111111111111111111111111111111111111111 in binary.

  • Comment on Re: decimal to binary conversion need help

Replies are listed 'Best First'.
Re^2: decimal to binary conversion need help
by Anonymous Monk on Jan 06, 2005 at 12:15 UTC
    thank you but i need a perl code thank u

      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";'