HEX Values and strings


if have hex value of 0b , want show string, leading 0 droped, i.e. output "b" when converted string.

how suggest make hex value of 0b print "0b"?

i checking if value of hex less 16, adda "0" it.
code: [select]

if(instnumber <= 15)
       sinsert = "0"+itohex(instnumber);


but feel bit arcane.

edit
i think found answer, makestring()


edit edit
makestring work  ;)
forgot can pad values resulting in single character padded leading "0".

code: [select]

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 following, works hexvalues between 0 , $ff:
code: [select]
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


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > HEX Values and strings


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums