Dictionary learning for sparse representations is generally conducted in two alternating steps: sparse coding and dictionary updating. In this paper, a new approach to solve the sparse coding step is proposed. Because this step involves an 0-norm, most, if not all existing solutions only provide a local or approximate solution. Instead, a real 0 optimization is considered for the sparse coding problem providing a global solution. The proposed method reformulates the optimization problem as a Mixed-Integer Quadratic Program (MIQP), allowing then to obtain the global optimal solution by using an offthe-shelf optimization software. Because computing time is the main disadvantage of this approach, two techniques are proposed to improve its computational speed. One is to add suitable constraints and the other to use an appropriate initialization. The results obtained on an image denoising task demonstrate the feasibility of the MIQP approach for processing real images while achieving good performance compared to the most advanced methods.