Along the lines of How to encode integers into other integers, I am wondering if it is possible to encode one integer or a set of integers into one smaller integer or a smaller set of integers, and if so, how it is done. For example, encoding an 8 bit integer into a 4 bit integer, a 256 integer into a 16 bit integer. It doesn't seem possible but perhaps there is something along these lines. Basically, how to get a set of integers to take up less space. Not necessarily encoding into another sequence of bytes, but maybe even into a data structure that is more compact.
Asked
Active
Viewed 200 times
0
-
You know about the pigeonhole principle though right? So unless there is some expected distribution of inputs there's basically nothing to be done.. and even then there can only be compression on average, there must necessarily be expansions but they can be allocated to the rare inputs – harold Jul 10 '18 at 19:38
1 Answers
0
Sure, you can always encode them into fewer bits. However you won't be able to decode them back to the original bits. Though you neglected to mention that step, I'm guessing that's what you're looking for.

Mark Adler
- 101,978
- 13
- 118
- 158