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.

I think I found the answer, MakeString()

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".



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);

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