views:

30

answers:

3

I have a long list of integers, and i need to reduce this down to a single integer. The integer list can be anywhere from 0 to 300 ints long (about). I need to be able to encode/decode.

Is there a better option than a lookup table?

A: 

Any technique for reducing N bits of data to M bits of data, where M is less than N can only work for inputs that are redundant in some way. A reduction of 300:1 would require a huge amount of redundancy in the input (e.g., almost all the numbers were zeros).

Jerry Coffin
A: 

yea jerry thats what i thought. on most cases it will be most 0s, but other times it will not. and i will have much more than my 32 bits of integer.

ill just take the easy route and lookup table this. its their fault for changing requirements 3 months after i started this shit anyway.

asdasd
A: 

If you want to save some space and your list of 32-bit integers are statistically clustered around a certain range of values, you can use integer compression.

.NET uses integer compression for method metadata in IL assemblies. The idea is that if the integer is usually small (e.g. 1-100), you can save space by encoding it using far fewer than 32 bits. Depending on your scheme, you'll have to sacrifice a bit or two to tell the compressor/decompressor whether you have a small value or a large value.

See here for a deeper explanation of how .NET does it.

Chris Schmich