Funtion template for num_to_hex_string

And also make the util code header-only