HEX Values and strings

If I have a HEX Value of 0B and I want to show that as a string, the leading 0 is droped, i.e. the output is "B" when converted to a string.

How would you suggest to make a HEX value of 0B print as "0B"?

I do it now by checking if the value of the HEX is less than 16, then adda "0" to it.

if(InstNumber <= 15)
        sInsert = "0"+ItoHex(InstNumber);

but I feel that is a bit arcane.

EDIT
I think I found the answer, MakeString()

EDIT EDIT
MakeString will work :wink:
Forgot that I can pad the values so anything resulting in a single character will get padded with a leading "0".

MakeString(To_Device$,":X19%04X68N%02X%02X%02X%02X%02X%02X%02X%02X;\n",PGN,i_Byte[1],i_Byte[2],i_Byte[3],i_Byte[4],i_Byte[5],i_Byte[6],i_Byte[7],i_Byte[8]);

Hi,

try the following, it works for all hexvalues between 0 and $FF:

void loop()
{
   byte bb = 37;
   char shex[] = "00";
   shex[0] = NibbleToChar(bb >> 4);
   shex[1] = NibbleToChar(bb & 15);
   Serial.println(shex);
}

char NibbleToChar(byte b)
{
  b = b + 48;
  if (b > '9') b = b + 7;
  return b;
}

Mike