Concatenating Integer variables

Think of it in normal decimal numbers first. That way you can count on your fingers. Then turn it into binary later.

If you have a 1 and a 1 and you want to show this as 11, what is that number? It's eleven isn't it? Eleven is ten plus one. Ten is 1 times ten and one is just 1.

  intConcat= 10*intNo2 + intNo1

So in binary it's two. 1 times 2, 1 times 4 and so on. But I like to make the compiler do that work for me. In binary, two is 10. Notice the similarity to the decimal above?

Turning that into code...

  intConcat = 0b100*intNo3 + 0b10*intNo2 + intNo1;

Of course the input integers can only be 0 or 1, so you must add a check above this line to make sure every single one can only take one of those two values. One clever trick to do this is the not-not operation. Put a "!!" in front of each value so that the integer gets converted to a boolean, inverted, inverted back again and then the boolean is converted to an integer with the values 0 or 1.

  intConcat = 0b100*!!intNo3 + 0b10*!!intNo2 + !!intNo1;