Greetings All

I'm trying to output a a number "0" every second (to a text file) unless a bang is sent, in which case a number "1" will be written to the text file instead of a zero.  The problem I'm having is converting a bang into a number.  I tried using moses but moses has no number for bang.  Any work arounds?

Example:
bng
|
moses 1
|          |
0(         1(


Thanks