Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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";


Comment on Re: Converting Java to Perl (BigInteger)
Download Code

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 taking refuge in the Monastery: (8)
As of 2014-09-23 23:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls