itsanjan / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

String class does not convert to base HEX / hexadecimal #577

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
---------------------------------------
The following code outputs "13" rather than "D"

Code:
unsigned long test = 13;
String thisString = String(test, HEX);
Serial.println(thisString);

See - http://arduino.cc/forum/index.php/topic,66634.0.html

What is the expected output? What do you see instead?
------------------------------------------------------
Expected: D
See: 13

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?
--------------------------------------------
IDE 22 - windows 7 - 328

Please provide any additional information below.
-------------------------------------------------
File: Wstring.cpp 

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

Original issue reported on code.google.com by rob.till...@gmail.com on 5 Aug 2011 at 8:05

GoogleCodeExporter commented 9 years ago
This is fixed with the new String implementation coming in 1.0.

Original comment by dmel...@gmail.com on 24 Aug 2011 at 6:57