6/15 When Is A Number Too Big To Calculate Its Factorial? - Codecademy

If you ever heard the expression of 32-bit computers or 64-bit computers, then you are already pretty close to figuring out how large a number can be.

You probably know that computers calculate in binary (we humans commonly do in decimals). A bit is what we could call a digit. Now, the largest number you can achieve with one digit is 9. And with two digits it’s 99. And so on.

In binary, you usually have units with size either 32 bits or 64 bits respectively. I suggest you to learn how binary works but I try to make a quick analogy:

67 = 10^1 * 6 + 10^0 * 7 = 10 * 6 + 1 * 7 = 60 + 7 121 = 10^2 * 1 + 10^1 * 2 + 10^0 + 1 = 100 + 20 + 1

So each digit is related with a power of ten. In binary, it’s the same but with powers of two! Also, in binary, we only have the numbers 1 and 0. Thus:

10 = 2^1 * 1 + 2^0 * 0 = 2 * 1 + 1 * 0 = 2 + 0 = 2 1011 = 2^3 * 1 + 2^2 * 0 + 2^1 * 1 + 2^0 * 1 = 8 * 1 + 0 + 2 + 2 * 1 = 12

Now, assuming that we leave out negative numbers, with 32 bits, the largest numbers is 32 ones:

11111111111111111111111111111111 = 4,294,967,295

This is the same as 2^32 - 1 (a bit like doing 10^3 - 1 = 999 to get the largest 3 digit number in decimals).

You now know how to compute the largest number with 64 bits.

But! We can do even better! For this, we use the so called float type. They are a bit tricky to explain here. But their representation differs a lot from how what I showed you. So I suggest you make some research yourself.

Wait! And some programming languages offer even higher values by using something like a double! Which, iirc, simply gives you double the bits for your number. Iirc, they follow the same representation as floats. So basically, you can have numbers with 128 bits.

And finally, now that there are programming languages that allow you to compute numbers with arbitrary size and/or precision. I’m unfamiliar with how they do it, but I assume that they do some kind of variable concatenation. Basically, saying that digits 1 to x are in variable 1, from digit x+1 to 2*x are stored in variable 2 etc. But no guarantee here.

A little side note: those ranges are usually halfed if you allow negative numbers. Because they usually use the left-most bit to represent the sign, so you use one digit, which in binary is the same as halving the range.

I hope this helps :)

Tag » How To Do Factorials On Ti-84