Does anyone have a formula that compresses (or inflates based on what sequence of bits it is) of an 8-bit strand?

I've been trying to find a way to code it but it seams that I have to specify when-this-is-this-then-its-this routine.

Ex.

"1111 1111" is compressed into "1111"
-Starting with the first bit of 1, then if it repeats it is 1, if it repeats the 2 bits of it again then it is one. Then since it now cancels out the 3rd and 4th bits, if it repeats as all 4-bits for the next 4-bits then it's 1.

"0110 1001" by the same method is not compressed but inflated to "00 0 10 0 10 0 00"
-Starting with 0, does not repeat so it's another 0, and it does not repeat it's 2 bits as whole so another 0. Then by means the 3rd bit is used to start which is 1, it doesn't repeat so next is 0. And the 4 bits do not repeat as whole so it's another 0. By means the 1st bit of the next set is used which is 1, and it doesn't repeat so next is 0. The first 2 bits of the second set do not repeat so it's another 0. By means, again, starts with the 1st of the 2nd 2 bits which is 0. And it does not repeat so it's another 0.

There is also the cancelation rule.

"1110 1111" is compressed as "11 0 1X 111"
-Where X means it doesn't need the info since the first 2 bits are the same but do not repeat, then since the next 2 bits begin with a 1, it has no-choice but to be a 0, so that 0 does not need to be there and is not put in the output sequence.

I call this process Polarized compression, because the fact that it can be used in unlimited number of sets of 2 bits, and the more 0's than 1's or more 1's than 0's, can be compressed, deflated, inflated, decompressed to a loss-less data form based on its sequence.
So, no matter what, it can be compressed by means of using more than 8 bits to compress by using decompression or using less than 8 bits to decompress by compression.

I got it in all notes but the formula is lacking. Any suggestions?