Changed sprintf to chartohex function