This paper introduces control barrier functions for discrete-time systems, which can be shown to be necessary and sufficient for controlled invariance of a given set. Moreover, we propose nonlinear discrete-time control barrier functions for partially control affine systems that lead to controlled invariance conditions that are affine in the control input, leading to a tractable formulation that enables us to handle the safety optimal control problem for a broader range of applications with more complicated safety conditions than existing approaches. In addition, we develop mixed-integer formulations for basic and secondary Boolean compositions of multiple control barrier functions and further provide mixed-integer constraints for piecewise control barrier functions. Finally, we apply these discrete-time control barrier function tools to automotive safety problems of lane keeping and obstacle avoidance, which are shown to be effective in simulation.