The midi messages need to be in hex format, so I have to convert the variable (int or long) to hex.
Opcode and control number (passed as function argument) already are defined as their hex value, so using them around as int does the same. But the value part comes in as int, and needs to be converted to hex.
That conversion method was the only one I found anywhere.