MATLAB: How to pass a hexadecimal number, generated in MATLAB workspace, as an input to the C-MEX routine

hexhexadecimalMATLABmex

How do I pass a hexadecimal number, that was generated in MATLAB workspace, as an input to my C-MEX routine?
I am generating a hexadecimal number in MATLAB using the DEC2HEX function. I want to pass this hexadecimal number to a C MEX routine. How do I pass a hexadecimal number to my MEX routine and how do I interpret it in my C code?

Best Answer

The MATLAB function DEC2HEX returns the hexadecimal representation of a decimal integer as a string. If this value is passed as an argument to your MEX routine, it will be passed as a string and not as a hexadecimal number. In the C-MEX routine, you will need to parse the string and write your own routine to convert this string into a hexadecimal number.
Similarly, if you want to pass a hexadecimal number from C to MATLAB, you will have to pass the string representation of the hexadecimal number to MATLAB. You can then use HEX2DEC function to convert the string into a decimal number.