MIPS translator in C++, how to convert to hex

I am creating a translator in C++ that accepts MIPS assembly instructions such as "add 1, 2, 3" as in add register 2 and 3 and place the result in register 1. Eventually, I save everything into a string representing the machine code that is supposed to be the output, however I want to display it in hexadecimal format, instead it outputs in decimal