Problems on convert byte[] to String I'm reading a RFID Card from RC522 and send the data to my computer. My problem is the conversion of byte[] to String or std::string.

#define SIZE_BUFFER     18
#define MAX_SIZE_BLOCK  16

byte buffer[SIZE_BUFFER] = {0};
byte tam = SIZE_BUFFER;

// get data
status = mfrc522.MIFARE_Read(bloco, buffer, &amp;tam);

  Serial.print(F("\nDados bloco ["));
  Serial.print(F("]: "));

// printing...
 for (uint8_t i = 0; i &lt; MAX_SIZE_BLOCK; i++)
  {
      Serial.write(buffer[i]);
      str += String(buffer[i]);
  }


OUTPUT:

Dados bloco []: asdas


So, it's ok! But if I try make a string:

  String str = "";

  for (uint8_t i = 0; i &lt; MAX_SIZE_BLOCK; i++)
  {
      str += String(buffer[i]);
  }
  Serial.println(" ");
  Serial.println(str);


The output is:

97115100971153232323232323232323232


What is the correct way to create a String from byte[]?
byte and char are the same. If you set 0 as string terminator after last character in the buffer, you get a zero terminated string. If you really must use String, you can create an instance with a constructor that takes zero terminated string.

buffer[tam] = 0;
String str((char*) buffer);


Let in the buffer a place for the zero. (char*) is cast that says that the byte array is a char array. 

Note: Don't use String class in a MCU, use zero terminated character arrays.