An Algebraic Approach to Bang-Bang Control