Combinations with symbols Suppose we have the following symbols: $\{a,b\}$. Now there are some rules. More than 3 $b$'s are now allowed and $aa$ is not allowed. So $ababab$ is allowed, but for example $abbbbaba$ not (more than 3 $b$'s). There is an easy way to get this working. Suppose you have a string of $n$ characters. Just add between every two numbers a new number so the string is correct. Decoding is not hard: just remove all numbers on even positions. So $abbbbaba \rightarrow axbxbxbxbxaxbxax$ and decoding is the same as just removing the $x$'s. But the problem is that the string size doubles. Is there a more efficient way to accomplish encoding and decoding? So encoding means encode all strings to valid strings and decoding means decode that string back to the original string.
This is called run-length-limited coding, there has been lots of research done on it by the information theory community, and I will just refer you to the existing literature. After a brief glance at the wikipedia article I linked to, my impression is that you shouldn't rely on the references it contains, but do your own search of the literature. 

One simple thing you could do that does better than doubling the string size is: 

(1) add a 0 to the end of the original sequence, 
(2) break the original sequence greedily into blocks of either 0, 10, or 11, 
(3) encode using the encoding


  &thinsp;&thinsp;&thinsp;0 &rarr; ab
  10 &rarr; abb
  11 &rarr; abbb  


Step (2) is always possible, since after step (1) the sequence ends with a 0. Except for step (1), which adds at most two bits to your encoded sequence, this cannot do worse than double the string size, and generally does better.

For example, you encode 
0110100101 &rarr; 0.11.0.10.0.10.10 &rarr; ababbbababbababbabb, 
taking 10 characters into 19. 

If I did my calculations right, starting with $n$ random bits, this encoding gives an expected length of 11/6&thinsp;$n$ bits, which is only slightly more than the optimal value of around 1.813&thinsp;$n$ bits.