In your situation (when pattern repetition is not observed), variable-length coding can help you.
For example, Elias gamma coding and Exponential-Golomb coding . The general idea is that for small numbers only a few bits are required for encoding. Exp-Golomb encoding is used in the H.264 / MPEG-4 AVC video compression standard. It is very easy to encode and decode sequences with it; it is also not very difficult to implement this encoding.
The way to encode all integers is to set a bijection by mapping the integers (0, 1, -1, 2, -2, 3, -3, ...) to (1, 2, 3, 4, 5, 6, 7, ...) before encoding.
For instance:
The sequence (after the bijection) [ 0, 2, 5, 8, 5, 2 ] will be encoded as 101100110000100100110011 - As you can see, there are no repeating patterns in this sequence, but it is encoded with only 24 bits.
A brief description of the decoding process:
Reading from the input stream and counting the leading zero bits (until you find a non-zero bit value) → zero_bits_count
Reading from the input stream the next (zero_bits_count + 1) bit -> binary
Convert binary to decimal
Return (decimal - 1)
1... -> no leading zeros, zero_bits_count = 0 -> read next 1 bit -> [1]... -> [1] is 1 -> 1 - 1 = 0
011... -> [0] - one leading zero, zero_bits_count = 1 -> read next 2 bits -> [11]... -> [11] is 3 -> 3 - 1 = 2
00110... -> [00] - two leading zeros, zero_bits_count = 2 -> read next 3 bits -> [110]... -> [110] is 6 -> 6 - 1 = 5
and etc.