Saving Oscilloscope Traces as Compressed Bitstream
Depending upon the ratio between the average period and the frequency of state changes, some form of run-length encoding may be the most effective approach.  That would be especially true if the only things of interest are long runs of high, long runs of low, or periods that can't be characterized as other [e.g.
if the shortest runs of interest are length 4, then something like

 111111110010100010000000


would be reduced to "eight ones, followed by nine unstable bits, followed by
eight zeros".  In the cases where the number of unstable bits is zero or one, there would be no need to store the polarity of the next stable run [following zero unstable bits, it would be the opposite of the previous; following one it would be the same as the previous].