Removing digital noise in software
From your latest comment, I would suggest oversampling the input.  Record several consecutive samples, and then your output should be whatever the majority of the recorded samples are.

For instance, say you record 10 samples.  If you get a noise spike, only one or two of the samples will be corrupted, while the majority of them are the correct value.  If you get actual data, then eventually the 1s will outnumber the 0s and the output will change.