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.

  • $\begingroup$ This is a computer science question, not a mathematics question. $\endgroup$ – rschwieb Feb 6 at 19:57
  • 4
    $\begingroup$ 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. $\endgroup$ – L. Scott Johnson Feb 6 at 19:57
  • 1
    $\begingroup$ 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. $\endgroup$ – jmacmanus Feb 6 at 20:01
  • $\begingroup$ 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). $\endgroup$ – whiskeyo Feb 6 at 20:05
  • 2
    $\begingroup$ 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$. $\endgroup$ – Robert Israel Feb 6 at 20:45

Via pigeonhole principle, you can't, if you want lossless compression. any compression algorithm that force some lower in bitstring length, will force others higher if it avoids overlap and is therefore lossless.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.