tags:

views:

231

answers:

2

I have a really big number in Perl. I use "bignum". How can I extract single digits out of this big number. For example if I have a number like this and what to get the 3rd digit from the end:

1029384710985234058763045203948520945862986209845729034856

-> 8

+11  A: 

bignums are transparently available, so this will work:

$digit = substr($bignum, -3, 1);
Jeremy Smyth
+7  A: 

The bignum package uses Math::BigInt under the hood for integers.

From the Math::BigInt man page:

$x->digit($n);        # return the nth digit, counting from right

Note that counting starts at 0 for the rightmost digit.

Lars Haugseth