Using big numbers in Perl -


i have scenario take 2 big binary strings (having 100 characters) , need add them.

the issue getting answer in form 2.000xxxxxxxxxxe+2, whereas need precise answer, 100 character long string.

chomp($str1=<stdin>); chomp($str2=<stdin>); print "str 1 $str1\n"; print "str 2 $str2\n"; $t = $str1 + $str2; print "sum $t\n"; 

sample input

1001101111101011011100101100100110111011111011000100111100111110111101011011011100111001100011111010 1001101111101011011100101100100110111011111011000100111100111110111101011011011100111001100011111010 

sample output
str1

1001101111101011011100101100100110111011111011000100111100111110111101011011011100111001100011111010       

str2

1001101111101011011100101100100110111011111011000100111100111110111101011011011100111001100011111010 

sum

2.0022022220202e+099 

as suggested, can use math::bigint core module,

use math::bigint;  # chomp($str1=<stdin>); # chomp($str2=<stdin>); # print "str 1 $str1\n"; # print "str 2 $str2\n";  $t = math::bigint->new("0b$str1") + math::bigint->new("0b$str2");  print $t->as_bin; 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -