user46709: How can i concatenate integers as a single string?
int out1, out2, out3 = 0;

    out1 = digitalRead(r1);
    out2 = digitalRead(r2);
    out3 = digitalRead(r3);

I tried like so, between others, with no luck.
Serial.write(out1 + "" + out2 + "" + out3);

For example the expected result when all outputs are HIGH should be 111, while when only the r3 output is HIGH it should be 001 
All i want, is reporting to the sender of the serial command, the pins state

user7508: I second Majenko's points about just printing the bits separately if
possible, and avoiding String objects.
However, if you do need to build such a string (not String object, just
plain C string), you don't need sprintf(), which is quite a big
function: you can build the string character by character. For example:
char out[4];  // 3 + 1 char for the termination character
out[0] = out1==HIGH ? '1' : '0';
out[1] = out2==HIGH ? '1' : '0';
out[2] = out3==HIGH ? '1' : '0';
out[3] = '\0';  // add NUL termination
Serial.println(out);

This is using the ternary operator, which here means “if out1 is
HIGH, then use the character '1', otherwise use '0'”.
Now, it just happens that in Arduino HIGH means 1 and LOW means 0.
And single digit numbers can be converted into character by just adding
the numeric code of character “0”, which is 48 but can written as '0'
in C++. Thus you can write:
out[0] = out1 + '0';  // convert number to character

And you can put all together as:
char out[4];  // 3 + 1 char for the termination character
out[0] = digitalRead(r1) + '0';
out[1] = digitalRead(r2) + '0';
out[2] = digitalRead(r3) + '0';
out[3] = '\0';  // add NUL termination
Serial.println(out);


user37622: Serial.write(b) prints one byte not a string. Use print() to print strings and numbers.
Serial.print(digitalRead(r1));
Serial.print(digitalRead(r2));
Serial.println(digitalRead(r3));


user4143: If you're just outputting to serial you don't need to concatenate - just print each bit separately, such as:
Serial.print(out1);
Serial.print(",");
Serial.print(out2);
Serial.print(",");
Serial.println(out3);

You should avoid using String as it's not good on devices with small amounts of memory like Arduinos. Instead if you really need to concatenate numbers you should use a C string and maybe snprintf to format the numbers into it:
char out[30];
snprintf(out, 30, "%d,%d,%d", out1, out2, out3);


46709: <p>How can i concatenate integers as a single string?</p>

<pre><code>int out1, out2, out3 = 0;

    out1 = digitalRead(r1);
    out2 = digitalRead(r2);
    out3 = digitalRead(r3);
</code></pre>

<p>I tried like so, between others, with no luck.</p>

<pre><code>Serial.write(out1 + "" + out2 + "" + out3);
</code></pre>

<p>For example the expected result when all outputs are <code>HIGH</code> should be <code>111</code>, while when only the <code>r3</code> output is <code>HIGH</code> it should be <code>001</code> </p>

<p>All i want, is reporting to the sender of the serial command, the pins state</p>
 7508: <p>I second Majenko's points about just printing the bits separately if
possible, and avoiding <code>String</code> objects.</p>

<p>However, if you do need to build such a string (not String object, just
plain C string), you don't need <code>sprintf()</code>, which is quite a big
function: you can build the string character by character. For example:</p>



<pre class="lang-c++ prettyprint-override"><code>char out[4];  // 3 + 1 char for the termination character
out[0] = out1==HIGH ? '1' : '0';
out[1] = out2==HIGH ? '1' : '0';
out[2] = out3==HIGH ? '1' : '0';
out[3] = '\0';  // add NUL termination
Serial.println(out);
</code></pre>

<p>This is using the <a href="https://en.wikipedia.org/wiki/%3F:#C" rel="nofollow noreferrer">ternary operator</a>, which here means “if <code>out1</code> is
<code>HIGH</code>, then use the character <code>'1'</code>, otherwise use <code>'0'</code>”.</p>

<p>Now, it just happens that in Arduino <code>HIGH</code> means 1 and <code>LOW</code> means 0.
And single digit numbers can be converted into character by just adding
the numeric code of character “0”, which is 48 but can written as <code>'0'</code>
in C++. Thus you can write:</p>

<pre class="lang-c++ prettyprint-override"><code>out[0] = out1 + '0';  // convert number to character
</code></pre>

<p>And you can put all together as:</p>

<pre class="lang-c++ prettyprint-override"><code>char out[4];  // 3 + 1 char for the termination character
out[0] = digitalRead(r1) + '0';
out[1] = digitalRead(r2) + '0';
out[2] = digitalRead(r3) + '0';
out[3] = '\0';  // add NUL termination
Serial.println(out);
</code></pre>
 37622: <p>Serial.write(b) prints one byte not a string. Use print() to print strings and numbers.</p>

<pre><code>Serial.print(digitalRead(r1));
Serial.print(digitalRead(r2));
Serial.println(digitalRead(r3));
</code></pre>
 4143: <p>If you're just outputting to serial you don't need to concatenate - just print each bit separately, such as:</p>

<pre><code>Serial.print(out1);
Serial.print(",");
Serial.print(out2);
Serial.print(",");
Serial.println(out3);
</code></pre>

<p>You should avoid using String as it's not good on devices with small amounts of memory like Arduinos. Instead if you really need to concatenate numbers you should use a C string and maybe <code>snprintf</code> to format the numbers into it:</p>

<pre><code>char out[30];
snprintf(out, 30, "%d,%d,%d", out1, out2, out3);
</code></pre>
