I have an array which contains data within range -255 to +255.e.g. The array can be like this:
int data[]={234,56,-4,24,56,78,23,89,234,68,-12,-253,45,128};
Here, order must be preserved while decompressing e.g. after 1st term 234, 56 must come.
So, what are the ways to compress any arbitrary sequence of numbers for which any repeating pattern can’t be observed?
A range of -255 to 255 means 511 values -> 9 bits. If you take the sign separately, 1 bit for sign and a byte for value.
You can write your array as a byte array, each byte value will be the absolute value of the related int.
In a separate zone (a long, or perhaps a byte array), store the sign bit.