Problem:  When I use sprintf to convert a byte to Hex, negative values are
prefixed with FF even when I force format to 2 characters or cast as an
unsigned integer.  I have tried numerous approaches, all which point to a
forced signed int inside the sprintf funcion.

void write0_byte_to_hex(char *s){
  char sresult[4];
  unsigned int i;
   i = s[0];
   sprintf(sresult, "%02X", i);
    uart_enq(&uart0, sresult);
}

For the above code, if s[0] = 0xD5, the sprintf result is "FFD5"

I have looked through the FAQ's and forums for a resolution to this but
didn't find a solution.  I have a work around but I am afraid that
nonobvious bugs will be introduced when sprintf is fixed.

Thanks,
Gene

<<attachment: winmail.dat>>

Reply via email to