Convert long to hex string

Week 1 Arduino newbie:)
I'm decoding IR codes using Ken Sherriff's IRLibrary but I'm having problems in checking for particular codes

This code

...
unsigned long codeValue;
...
(use lib to get a value)
...
   Serial.println(codeValue);
    String sCodeValue = String(2576,HEX);
    Serial.println(sCodeValue);
    sCodeValue = String(codeValue,HEX);
    Serial.println(sCodeValue);

produces

2576
a10
2576

whereas I was expecting/hoping for

2576
a10
a10

Can someone tell me what language error I've made please? :slight_smile:
(Basically I'd like to compare sCodeValue against a set of values but I have those values in Hex so I don't want to have to translate them all to decimal)

regards

Simon

This is a known bug in the String class, which is reported. - http://code.google.com/p/arduino/issues/detail?id=577&q=String%20class -

The fix is in the file: Wstring.cpp (windows under C:\Program Files (x86)\arduino-0022\hardware\arduino\cores\arduino )

String::String( const unsigned long value, const int base )
{
char buf[33];
ultoa(value, buf, 10);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}

should be changed in

String::String( const unsigned long value, const int base )
{
char buf[33];
ultoa(value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}

Phew - I'm glad it wasn't me :slight_smile:
Thanks

Si

Applied your fix - working fine now - Ta :slight_smile:
Simon