Skip to main content
Golf 1 by memory wrap, 12 by numerical return as appears to be accepted style. Some comment improvements. New TIO.
Source Link

Brainfuck, 85 bytes

Brainfuck, 85 72 (84) bytes

>,[>-[-----<->]<++[>++++[-<++++>]+<[[<++++>]+<[[+],[[-]]>-<]]]>[<<+[-->]>[<],>-]<]<+.

to return numerically, or

,[>-[-----<->]<++[>++++[-<++++>]+<[[+],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

[Online version][1]for ASCII text. > may also be prefixed to avoid memory wrapping.

Try it online!


Loops over the input.
On 1, ends.
On "!", toggles bool a booleanstored as 0 or 255.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

>,                  setup first input 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # case not "1"
    >++++[-<++++>]      add 16 since 49 take 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # case "0"
      [+],                clear and new INPUT
      [                     # trailingcase "0!"
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # case "!" or "0" without tail
    <<+[-->]>[<]        not the BOOL
    ,                   take new INPUTinput
    >-                  clear FLAG
  ]
  <                   move to INPUT
] 

+.                    return 0 or 1

Or for text response, replace the last line with

-[-----<+>]<--.       add 49 for "0" or "1" conversion and return

I think some bytes might be saved by changing to a (not 1)>(not 0) structure to avoid the +16, but have so far found the extra flag bytes needed added too much.

Thanks to the lovely people in meta for help posting. [1]: https://copy.sh/brainfuck/?c=TWVtb3J5IGxhYmVscyAgfCBCT09MIHwgSU5QVVQgfCBGTEFHIHwKCj4sICAgICAgICAgICAgICAgICAgc2V0dXAgClsgICAgICAgICAgICAgICAgICAgICAjIGxvb3Agb24gSU5QVVQKICA-LVstLS0tLTwtPl08KysgICAgIHN1YnRyYWN0IDQ5ID09ICIxIgoKICBbICAgICAgICAgICAgICAgICAgICAgIyBub3QgIjEiCiAgICA-KysrK1stPCsrKys-XSAgICAgIGFkZCAxNiBzaW5jZSA0OSB0YWtlIDE2ID09ICIhIgogICAgCiAgICArICAgICAgICAgICAgICAgICAgIHNldCBGTEFHCiAgICA8ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gSU5QVVQKICAgIFsgICAgICAgICAgICAgICAgICAgICAjICIwIgogICAgICBbK10sICAgICAgICAgICAgICAgIGNsZWFyIGFuZCBuZXcgSU5QVVQKICAgICAgWyAgICAgICAgICAgICAgICAgICAgICMgdHJhaWxpbmcgIQogICAgICAgIFstXT4tPCAgICAgICAgICAgICAgY2xlYXIgSU5QVVQgYW5kIEZMQUcKICAgICAgXQogICAgXQogIF0KICAKICA-ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gRkxBRwogIFsgICAgICAgICAgICAgICAgICAgICAjICIhIiBvciB0YWlsCiAgICA8PCtbLS0-XT5bPF0gICAgICAgIG5vdCBCT09MCiAgICAsICAgICAgICAgICAgICAgICAgIG5ldyBJTlBVVAogICAgPi0gICAgICAgICAgICAgICAgICBjbGVhciBGTEFHCiAgXQogIDwgICAgICAgICAgICAgICAgICAgbW92ZSB0byBJTlBVVApdCgotWy0tLS0tPCs-XTwtLS4gICAgIGFkZCA0OSBhbmQgcmV0dXJu

Brainfuck, 85 bytes

>,[>-[-----<->]<++[>++++[-<++++>]+<[[-],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

[Online version][1]

Loops over the input.
On 1, ends.
On "!", toggles a boolean.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

>,                  setup 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # not "1"
    >++++[-<++++>]      add 16 since 49 take 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # "0"
      [+],                clear and new INPUT
      [                     # trailing !
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # "!" or tail
    <<+[-->]>[<]        not BOOL
    ,                   new INPUT
    >-                  clear FLAG
  ]
  <                   move to INPUT
]

-[-----<+>]<--.     add 49 and return

I think some bytes might be saved by changing to a (not 1)>(not 0) structure to avoid the +16, but have so far found the extra flag bytes needed added too much.

Thanks to the lovely people in meta for help posting. [1]: https://copy.sh/brainfuck/?c=TWVtb3J5IGxhYmVscyAgfCBCT09MIHwgSU5QVVQgfCBGTEFHIHwKCj4sICAgICAgICAgICAgICAgICAgc2V0dXAgClsgICAgICAgICAgICAgICAgICAgICAjIGxvb3Agb24gSU5QVVQKICA-LVstLS0tLTwtPl08KysgICAgIHN1YnRyYWN0IDQ5ID09ICIxIgoKICBbICAgICAgICAgICAgICAgICAgICAgIyBub3QgIjEiCiAgICA-KysrK1stPCsrKys-XSAgICAgIGFkZCAxNiBzaW5jZSA0OSB0YWtlIDE2ID09ICIhIgogICAgCiAgICArICAgICAgICAgICAgICAgICAgIHNldCBGTEFHCiAgICA8ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gSU5QVVQKICAgIFsgICAgICAgICAgICAgICAgICAgICAjICIwIgogICAgICBbK10sICAgICAgICAgICAgICAgIGNsZWFyIGFuZCBuZXcgSU5QVVQKICAgICAgWyAgICAgICAgICAgICAgICAgICAgICMgdHJhaWxpbmcgIQogICAgICAgIFstXT4tPCAgICAgICAgICAgICAgY2xlYXIgSU5QVVQgYW5kIEZMQUcKICAgICAgXQogICAgXQogIF0KICAKICA-ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gRkxBRwogIFsgICAgICAgICAgICAgICAgICAgICAjICIhIiBvciB0YWlsCiAgICA8PCtbLS0-XT5bPF0gICAgICAgIG5vdCBCT09MCiAgICAsICAgICAgICAgICAgICAgICAgIG5ldyBJTlBVVAogICAgPi0gICAgICAgICAgICAgICAgICBjbGVhciBGTEFHCiAgXQogIDwgICAgICAgICAgICAgICAgICAgbW92ZSB0byBJTlBVVApdCgotWy0tLS0tPCs-XTwtLS4gICAgIGFkZCA0OSBhbmQgcmV0dXJu

Brainfuck, 85 72 (84) bytes

,[>-[-----<->]<++[>++++[-<++++>]+<[[+],[[-]>-<]]]>[<<+[-->]>[<],>-]<]<+.

to return numerically, or

,[>-[-----<->]<++[>++++[-<++++>]+<[[+],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

for ASCII text. > may also be prefixed to avoid memory wrapping.

Try it online!


Loops over the input.
On 1, ends.
On "!", toggles bool a stored as 0 or 255.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

,                   first input 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # case not "1"
    >++++[-<++++>]      add 16 since 49 take 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # case "0"
      [+],                clear and new INPUT
      [                     # case "0!"
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # case "!" or "0" without tail
    <<+[-->]>[<]        not the BOOL
    ,                   take new input
    >-                  clear FLAG
  ]
  <                   move to INPUT
] 

+.                    return 0 or 1

Or for text response, replace the last line with

-[-----<+>]<--.       add 49 for "0" or "1" conversion and return
title format
Source Link

85 bytes Brainfuck

Brainfuck, 85 bytes

>,[>-[-----<->]<++[>++++[-<++++>]+<[[-],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

[Online version][1]

Loops over the input.
On 1, ends.
On "!", toggles a boolean.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

>,                  setup 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # not "1"
    >++++[-<++++>]      add 16 since 49 take 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # "0"
      [+],                clear and new INPUT
      [                     # trailing !
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # "!" or tail
    <<+[-->]>[<]        not BOOL
    ,                   new INPUT
    >-                  clear FLAG
  ]
  <                   move to INPUT
]

-[-----<+>]<--.     add 49 and return

I think some bytes might be saved by changing to a (not 1)>(not 0) structure to avoid the +16, but have so far found the extra flag bytes needed added too much.

Thanks to the lovely people in meta for help posting. [1]: https://copy.sh/brainfuck/?c=TWVtb3J5IGxhYmVscyAgfCBCT09MIHwgSU5QVVQgfCBGTEFHIHwKCj4sICAgICAgICAgICAgICAgICAgc2V0dXAgClsgICAgICAgICAgICAgICAgICAgICAjIGxvb3Agb24gSU5QVVQKICA-LVstLS0tLTwtPl08KysgICAgIHN1YnRyYWN0IDQ5ID09ICIxIgoKICBbICAgICAgICAgICAgICAgICAgICAgIyBub3QgIjEiCiAgICA-KysrK1stPCsrKys-XSAgICAgIGFkZCAxNiBzaW5jZSA0OSB0YWtlIDE2ID09ICIhIgogICAgCiAgICArICAgICAgICAgICAgICAgICAgIHNldCBGTEFHCiAgICA8ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gSU5QVVQKICAgIFsgICAgICAgICAgICAgICAgICAgICAjICIwIgogICAgICBbK10sICAgICAgICAgICAgICAgIGNsZWFyIGFuZCBuZXcgSU5QVVQKICAgICAgWyAgICAgICAgICAgICAgICAgICAgICMgdHJhaWxpbmcgIQogICAgICAgIFstXT4tPCAgICAgICAgICAgICAgY2xlYXIgSU5QVVQgYW5kIEZMQUcKICAgICAgXQogICAgXQogIF0KICAKICA-ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gRkxBRwogIFsgICAgICAgICAgICAgICAgICAgICAjICIhIiBvciB0YWlsCiAgICA8PCtbLS0-XT5bPF0gICAgICAgIG5vdCBCT09MCiAgICAsICAgICAgICAgICAgICAgICAgIG5ldyBJTlBVVAogICAgPi0gICAgICAgICAgICAgICAgICBjbGVhciBGTEFHCiAgXQogIDwgICAgICAgICAgICAgICAgICAgbW92ZSB0byBJTlBVVApdCgotWy0tLS0tPCs-XTwtLS4gICAgIGFkZCA0OSBhbmQgcmV0dXJu

85 bytes Brainfuck

>,[>-[-----<->]<++[>++++[-<++++>]+<[[-],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

[Online version][1]

Loops over the input.
On 1, ends.
On "!", toggles a boolean.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

>,                  setup 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # not "1"
    >++++[-<++++>]      add 16 since 49 take 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # "0"
      [+],                clear and new INPUT
      [                     # trailing !
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # "!" or tail
    <<+[-->]>[<]        not BOOL
    ,                   new INPUT
    >-                  clear FLAG
  ]
  <                   move to INPUT
]

-[-----<+>]<--.     add 49 and return

I think some bytes might be saved by changing to a (not 1)>(not 0) structure to avoid the +16, but have so far found the extra flag bytes needed added too much.

Thanks to the lovely people in meta for help posting. [1]: https://copy.sh/brainfuck/?c=TWVtb3J5IGxhYmVscyAgfCBCT09MIHwgSU5QVVQgfCBGTEFHIHwKCj4sICAgICAgICAgICAgICAgICAgc2V0dXAgClsgICAgICAgICAgICAgICAgICAgICAjIGxvb3Agb24gSU5QVVQKICA-LVstLS0tLTwtPl08KysgICAgIHN1YnRyYWN0IDQ5ID09ICIxIgoKICBbICAgICAgICAgICAgICAgICAgICAgIyBub3QgIjEiCiAgICA-KysrK1stPCsrKys-XSAgICAgIGFkZCAxNiBzaW5jZSA0OSB0YWtlIDE2ID09ICIhIgogICAgCiAgICArICAgICAgICAgICAgICAgICAgIHNldCBGTEFHCiAgICA8ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gSU5QVVQKICAgIFsgICAgICAgICAgICAgICAgICAgICAjICIwIgogICAgICBbK10sICAgICAgICAgICAgICAgIGNsZWFyIGFuZCBuZXcgSU5QVVQKICAgICAgWyAgICAgICAgICAgICAgICAgICAgICMgdHJhaWxpbmcgIQogICAgICAgIFstXT4tPCAgICAgICAgICAgICAgY2xlYXIgSU5QVVQgYW5kIEZMQUcKICAgICAgXQogICAgXQogIF0KICAKICA-ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gRkxBRwogIFsgICAgICAgICAgICAgICAgICAgICAjICIhIiBvciB0YWlsCiAgICA8PCtbLS0-XT5bPF0gICAgICAgIG5vdCBCT09MCiAgICAsICAgICAgICAgICAgICAgICAgIG5ldyBJTlBVVAogICAgPi0gICAgICAgICAgICAgICAgICBjbGVhciBGTEFHCiAgXQogIDwgICAgICAgICAgICAgICAgICAgbW92ZSB0byBJTlBVVApdCgotWy0tLS0tPCs-XTwtLS4gICAgIGFkZCA0OSBhbmQgcmV0dXJu

Brainfuck, 85 bytes

>,[>-[-----<->]<++[>++++[-<++++>]+<[[-],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

[Online version][1]

Loops over the input.
On 1, ends.
On "!", toggles a boolean.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

>,                  setup 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # not "1"
    >++++[-<++++>]      add 16 since 49 take 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # "0"
      [+],                clear and new INPUT
      [                     # trailing !
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # "!" or tail
    <<+[-->]>[<]        not BOOL
    ,                   new INPUT
    >-                  clear FLAG
  ]
  <                   move to INPUT
]

-[-----<+>]<--.     add 49 and return

I think some bytes might be saved by changing to a (not 1)>(not 0) structure to avoid the +16, but have so far found the extra flag bytes needed added too much.

Thanks to the lovely people in meta for help posting. [1]: https://copy.sh/brainfuck/?c=TWVtb3J5IGxhYmVscyAgfCBCT09MIHwgSU5QVVQgfCBGTEFHIHwKCj4sICAgICAgICAgICAgICAgICAgc2V0dXAgClsgICAgICAgICAgICAgICAgICAgICAjIGxvb3Agb24gSU5QVVQKICA-LVstLS0tLTwtPl08KysgICAgIHN1YnRyYWN0IDQ5ID09ICIxIgoKICBbICAgICAgICAgICAgICAgICAgICAgIyBub3QgIjEiCiAgICA-KysrK1stPCsrKys-XSAgICAgIGFkZCAxNiBzaW5jZSA0OSB0YWtlIDE2ID09ICIhIgogICAgCiAgICArICAgICAgICAgICAgICAgICAgIHNldCBGTEFHCiAgICA8ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gSU5QVVQKICAgIFsgICAgICAgICAgICAgICAgICAgICAjICIwIgogICAgICBbK10sICAgICAgICAgICAgICAgIGNsZWFyIGFuZCBuZXcgSU5QVVQKICAgICAgWyAgICAgICAgICAgICAgICAgICAgICMgdHJhaWxpbmcgIQogICAgICAgIFstXT4tPCAgICAgICAgICAgICAgY2xlYXIgSU5QVVQgYW5kIEZMQUcKICAgICAgXQogICAgXQogIF0KICAKICA-ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gRkxBRwogIFsgICAgICAgICAgICAgICAgICAgICAjICIhIiBvciB0YWlsCiAgICA8PCtbLS0-XT5bPF0gICAgICAgIG5vdCBCT09MCiAgICAsICAgICAgICAgICAgICAgICAgIG5ldyBJTlBVVAogICAgPi0gICAgICAgICAgICAgICAgICBjbGVhciBGTEFHCiAgXQogIDwgICAgICAgICAgICAgICAgICAgbW92ZSB0byBJTlBVVApdCgotWy0tLS0tPCs-XTwtLS4gICAgIGFkZCA0OSBhbmQgcmV0dXJu

changed - in comments to "take"
Source Link

85 bytes Brainfuck

>,[>-[-----<->]<++[>++++[-<++++>]+<[[-],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

[Online version][1]

Loops over the input.
On 1, ends.
On "!", toggles a boolean.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

>,                  setup 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # not "1"
    >++++[-<++++>]      add 16 since 49 -take 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # "0"
      [+],                clear and new INPUT
      [                     # trailing !
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # "!" or tail
    <<+[-->]>[<]        not BOOL
    ,                   new INPUT
    >-                  clear FLAG
  ]
  <                   move to INPUT
]

-[-----<+>]<--.     add 49 and return

I think some bytes might be saved by changing to a (not 1)>(not 0) structure to avoid the +16, but have so far found the extra flag bytes needed added too much.

Thanks to the lovely people in meta for help posting. [1]: https://copy.sh/brainfuck/?c=TWVtb3J5IGxhYmVscyAgfCBCT09MIHwgSU5QVVQgfCBGTEFHIHwKCj4sICAgICAgICAgICAgICAgICAgc2V0dXAgClsgICAgICAgICAgICAgICAgICAgICAjIGxvb3Agb24gSU5QVVQKICA-LVstLS0tLTwtPl08KysgICAgIHN1YnRyYWN0IDQ5ID09ICIxIgoKICBbICAgICAgICAgICAgICAgICAgICAgIyBub3QgIjEiCiAgICA-KysrK1stPCsrKys-XSAgICAgIGFkZCAxNiBzaW5jZSA0OSB0YWtlIDE2ID09ICIhIgogICAgCiAgICArICAgICAgICAgICAgICAgICAgIHNldCBGTEFHCiAgICA8ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gSU5QVVQKICAgIFsgICAgICAgICAgICAgICAgICAgICAjICIwIgogICAgICBbK10sICAgICAgICAgICAgICAgIGNsZWFyIGFuZCBuZXcgSU5QVVQKICAgICAgWyAgICAgICAgICAgICAgICAgICAgICMgdHJhaWxpbmcgIQogICAgICAgIFstXT4tPCAgICAgICAgICAgICAgY2xlYXIgSU5QVVQgYW5kIEZMQUcKICAgICAgXQogICAgXQogIF0KICAKICA-ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gRkxBRwogIFsgICAgICAgICAgICAgICAgICAgICAjICIhIiBvciB0YWlsCiAgICA8PCtbLS0-XT5bPF0gICAgICAgIG5vdCBCT09MCiAgICAsICAgICAgICAgICAgICAgICAgIG5ldyBJTlBVVAogICAgPi0gICAgICAgICAgICAgICAgICBjbGVhciBGTEFHCiAgXQogIDwgICAgICAgICAgICAgICAgICAgbW92ZSB0byBJTlBVVApdCgotWy0tLS0tPCs-XTwtLS4gICAgIGFkZCA0OSBhbmQgcmV0dXJu

85 bytes Brainfuck

>,[>-[-----<->]<++[>++++[-<++++>]+<[[-],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

[Online version][1]

Loops over the input.
On 1, ends.
On "!", toggles a boolean.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

>,                  setup 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # not "1"
    >++++[-<++++>]      add 16 since 49 - 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # "0"
      [+],                clear and new INPUT
      [                     # trailing !
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # "!" or tail
    <<+[-->]>[<]        not BOOL
    ,                   new INPUT
    >-                  clear FLAG
  ]
  <                   move to INPUT
]

-[-----<+>]<--.     add 49 and return

I think some bytes might be saved by changing to a (not 1)>(not 0) structure to avoid the +16, but have so far found the extra flag bytes needed added too much.

Thanks to the lovely people in meta for help posting. [1]: https://copy.sh/brainfuck/?c=TWVtb3J5IGxhYmVscyAgfCBCT09MIHwgSU5QVVQgfCBGTEFHIHwKCj4sICAgICAgICAgICAgICAgICAgc2V0dXAgClsgICAgICAgICAgICAgICAgICAgICAjIGxvb3Agb24gSU5QVVQKICA-LVstLS0tLTwtPl08KysgICAgIHN1YnRyYWN0IDQ5ID09ICIxIgoKICBbICAgICAgICAgICAgICAgICAgICAgIyBub3QgIjEiCiAgICA-KysrK1stPCsrKys-XSAgICAgIGFkZCAxNiBzaW5jZSA0OSB0YWtlIDE2ID09ICIhIgogICAgCiAgICArICAgICAgICAgICAgICAgICAgIHNldCBGTEFHCiAgICA8ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gSU5QVVQKICAgIFsgICAgICAgICAgICAgICAgICAgICAjICIwIgogICAgICBbK10sICAgICAgICAgICAgICAgIGNsZWFyIGFuZCBuZXcgSU5QVVQKICAgICAgWyAgICAgICAgICAgICAgICAgICAgICMgdHJhaWxpbmcgIQogICAgICAgIFstXT4tPCAgICAgICAgICAgICAgY2xlYXIgSU5QVVQgYW5kIEZMQUcKICAgICAgXQogICAgXQogIF0KICAKICA-ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gRkxBRwogIFsgICAgICAgICAgICAgICAgICAgICAjICIhIiBvciB0YWlsCiAgICA8PCtbLS0-XT5bPF0gICAgICAgIG5vdCBCT09MCiAgICAsICAgICAgICAgICAgICAgICAgIG5ldyBJTlBVVAogICAgPi0gICAgICAgICAgICAgICAgICBjbGVhciBGTEFHCiAgXQogIDwgICAgICAgICAgICAgICAgICAgbW92ZSB0byBJTlBVVApdCgotWy0tLS0tPCs-XTwtLS4gICAgIGFkZCA0OSBhbmQgcmV0dXJu

85 bytes Brainfuck

>,[>-[-----<->]<++[>++++[-<++++>]+<[[-],[[-]>-<]]]>[<<+[-->]>[<],>-]<]-[-----<+>]<--.

[Online version][1]

Loops over the input.
On 1, ends.
On "!", toggles a boolean.
On "0", toggles if there is no trailing bit, then ends.

Memory labels  | BOOL | INPUT | FLAG |

>,                  setup 
[                     # loop on INPUT
  >-[-----<->]<++     subtract 49 == "1"

  [                     # not "1"
    >++++[-<++++>]      add 16 since 49 take 16 == "!"
    
    +                   set FLAG
    <                   move to INPUT
    [                     # "0"
      [+],                clear and new INPUT
      [                     # trailing !
        [-]>-<              clear INPUT and FLAG
      ]
    ]
  ]
  
  >                   move to FLAG
  [                     # "!" or tail
    <<+[-->]>[<]        not BOOL
    ,                   new INPUT
    >-                  clear FLAG
  ]
  <                   move to INPUT
]

-[-----<+>]<--.     add 49 and return

I think some bytes might be saved by changing to a (not 1)>(not 0) structure to avoid the +16, but have so far found the extra flag bytes needed added too much.

Thanks to the lovely people in meta for help posting. [1]: https://copy.sh/brainfuck/?c=TWVtb3J5IGxhYmVscyAgfCBCT09MIHwgSU5QVVQgfCBGTEFHIHwKCj4sICAgICAgICAgICAgICAgICAgc2V0dXAgClsgICAgICAgICAgICAgICAgICAgICAjIGxvb3Agb24gSU5QVVQKICA-LVstLS0tLTwtPl08KysgICAgIHN1YnRyYWN0IDQ5ID09ICIxIgoKICBbICAgICAgICAgICAgICAgICAgICAgIyBub3QgIjEiCiAgICA-KysrK1stPCsrKys-XSAgICAgIGFkZCAxNiBzaW5jZSA0OSB0YWtlIDE2ID09ICIhIgogICAgCiAgICArICAgICAgICAgICAgICAgICAgIHNldCBGTEFHCiAgICA8ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gSU5QVVQKICAgIFsgICAgICAgICAgICAgICAgICAgICAjICIwIgogICAgICBbK10sICAgICAgICAgICAgICAgIGNsZWFyIGFuZCBuZXcgSU5QVVQKICAgICAgWyAgICAgICAgICAgICAgICAgICAgICMgdHJhaWxpbmcgIQogICAgICAgIFstXT4tPCAgICAgICAgICAgICAgY2xlYXIgSU5QVVQgYW5kIEZMQUcKICAgICAgXQogICAgXQogIF0KICAKICA-ICAgICAgICAgICAgICAgICAgIG1vdmUgdG8gRkxBRwogIFsgICAgICAgICAgICAgICAgICAgICAjICIhIiBvciB0YWlsCiAgICA8PCtbLS0-XT5bPF0gICAgICAgIG5vdCBCT09MCiAgICAsICAgICAgICAgICAgICAgICAgIG5ldyBJTlBVVAogICAgPi0gICAgICAgICAgICAgICAgICBjbGVhciBGTEFHCiAgXQogIDwgICAgICAgICAgICAgICAgICAgbW92ZSB0byBJTlBVVApdCgotWy0tLS0tPCs-XTwtLS4gICAgIGFkZCA0OSBhbmQgcmV0dXJu

Source Link
Loading