Conversion between boolean and int went wrong
Let me the first one to say that 1. Boolean to int conversion shouldn't be this complicated and 2. Much simpler ways to do what you are trying to do.

Like this.

If (bool) boolint |= mask;
  Mask = mask &lt;&lt; 1;
  ...

You get the idea.