# Storing numbers in an efficient way in computer.

I know that we can write a very large number such as 5040 in only 7!, and imagine I want to store this number in a binary file with the least number of bits.

Saving 5040 takes 13 bits of space, while saving it as 7 (knowing that 7 means 7!) takes only 3 bits. That occupies 4 times less space in a file.

Now I want to show numbers fro 0 to 4096, and if it's not possible, numbers 0 to 255 in any way that it takes less space to store it in binary systems.

I'm looking for ANY KIND OF WAYS (Fibonacci, Factorial, Algebra, Geometric positions, etc.) to do it in an efficient way. I welcome any idea about it. Thank you.

• This is a computer science question, not a mathematics question. – rschwieb Feb 6 at 19:57
• With 0 to 4095, you have 4096 distinct values to represent, so you need 12 bits. There's no way to do less and still have every possible value. – L. Scott Johnson Feb 6 at 19:57
• It's an interesting idea but I think Information Theory would have a thing or two to say if this was viable at all. Encoding n objects in a code will always require $\log_2 n$ bits. – jmacmanus Feb 6 at 20:01
• You should think about saving such data in numeral systems other than decimal, e.g. hexadecimal, or even bigger (think about creating your own, which will take less characters = less bits). – whiskeyo Feb 6 at 20:05
• You still don't seem to understand. It doesn't matter what kind of categorizations you use. There are only $2^n$ different strings of $n$ bits. You can't distinguish more than $2^n$ different objects with those bits. Of course, if you have "extra bits" to distinguish categories, those extra bits are counted in the $n$. – Robert Israel Feb 6 at 20:45