MATLAB: Questions about 64-bit stuff

floating pointnumerical representation

Here's my question based on what I understand from the book I'm reading. Hopefully, someone can understand my rough idea:
1) Say we have 64 bits. Each bit is either 0 or 1. So 64 bits can only have 64 spots to store 0s or 1s. But 10^380 is a very long (and huge number). We need 380 spots to write down 10^380, i.e., 10…000. Then how could it be possible for computer to store this number? I'm totally lost here.
2)"uint64" data type means computer require 64 bits to store such a number. The maximum integer of this type it can store is 2^64 – 1. Comparing to "double", which also uses 64 bits to store a fractions. Yet the largest number it can store is 1.79×10^380. 10^380 is a very very large number, in comparison to 2^64. How could this be? I mean why don't we just throw away (literally throw away) "uint64" because it uses the same amount of memory like "double" and can store even larger numbers.
Unless I'm crazy here, or misunderstand something. Someone please help explain.
Thanks.

Best Answer

You can write down 10^380 with even less than 64 bits: 6 bytes are enough (1 per character - it does not matter here that Matlab uses 2 bytes per char):
'1', '0', '^', '3', '8', '0'
But of course you have a limited accuracy with 6 characters. You can represent 11^381 also, but not 10.1^380. A similar effect occurs for the double format: You have one bit for the sign, some bits for the exponent and some for the mantissa. By this way you get about 16 digits and numbers up to 10^380. But you cannot store e.g. 18 valid digits in such a number due to the limited precision.
In uint64 you can store integers up to 2^64-1 exactly. The greater range of the double format is an effect of the limited precision of the mantissa. So you can see a double as 1 sign bit + a uint52 and a 11 bit exponent.