By the way, people have done exactly this already, and made nice libraries for it.

For example: The GNU MP Bignum Library