conv_to_hex: refactoring