Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Converting Java to Perl (BigInteger)

by tmharish (Friar)
on Feb 28, 2013 at 13:25 UTC ( #1021060=note: print w/replies, xml ) Need Help??


in reply to Converting Java to Perl (BigInteger)

Handle the sign and you should be fine: ( wow that rhymes! )

use strict ; use warnings ; use Math::BigInt ; my $hex = '-a' ; my $sign = '0' ; if( $hex =~ /^-/ ) { $hex =~ s/^-//g ; $sign = 1 ; } my $big_int = Math::BigInt->new( '0x'.$hex ) ; my $binary = $big_int->as_bin() ; my $two_comp = $binary ; $two_comp =~ s/^0b/$sign/; print "$two_comp\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2016-09-24 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (462 votes). Check out past polls.