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";
In reply to Re: Converting Java to Perl (BigInteger)
by tmharish
in thread Converting Java to Perl (BigInteger)
by kunimihk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |