How can I copy and compare a string?
There is this thing called &quot;operator precedence&quot; that defines the hierarchy of operators.
The ?: will be calculated after the +. That's why
s = s + digitalRead(2) ? &quot;1&quot; : &quot;0&quot;;

actually means
s = (s + digitalRead(2)) ? &quot;1&quot; : &quot;0&quot;;

But you want
s = s + (digitalRead(2) ? &quot;1&quot; : &quot;0&quot;);