Var holds a DEC value, need to convert to HEX for output to a device

I have a variable holding a decimal value, like 29. I need to send it to a device that only accepts hex, like $1D. Any suggestions for the conversion? Values will only be integers. Using a BS2
·
MyDec VAR byte
MyHex VAR byte
MyDec = 29
… Code needed here to put the value from MyDec into MyHex …
SEROUT· Pin,84,[noparse][[/noparse]…, MyHex, …]
·
In the above pseudo code STAMP would read out $1D for the MyHex argument of the SEROUT
·
The frustrating point is that the DEBUG HEX MyDec does this like a charm - but to the screen.·I need a hex conversion that put result·into a variable.
·
Right now I am embarrassed to say I do it by brute force. I run the MyDec value through a Select Case with three score options to cover my known set of possible values. Each case executes a MyHex = $xxx. There has to be something more clever.
·
Much thanks.
·
MyDec VAR byte
MyHex VAR byte
MyDec = 29
… Code needed here to put the value from MyDec into MyHex …
SEROUT· Pin,84,[noparse][[/noparse]…, MyHex, …]
·
In the above pseudo code STAMP would read out $1D for the MyHex argument of the SEROUT
·
The frustrating point is that the DEBUG HEX MyDec does this like a charm - but to the screen.·I need a hex conversion that put result·into a variable.
·
Right now I am embarrassed to say I do it by brute force. I run the MyDec value through a Select Case with three score options to cover my known set of possible values. Each case executes a MyHex = $xxx. There has to be something more clever.
·
Much thanks.
Comments
I tested & it works well
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office