tiny optimization of toHex function