title: efficient constant time conversion of boolean to int in java
body: <p>Constant time &amp; work evaluations of expressions are important to prevent side-channel attacks in cryptographic algorithms.  However, I am not aware of any constant-time conversions between false/true and 0/1 in Java.</p>
  
  <p>As a counter-example, </p>
  
  <pre><code>int x = p ? 1 : 0;
  </code></pre>
  
  <p>does not appear to have that property, since the branch in execution could mean there is a detectable difference in the evaluation of the expression.  In C/C++,</p>
  
  <pre><code>int x = p;
  </code></pre>
  
  <p>would do the trick, but this implicit conversion is not allowed in Java.  Is there a portable solution to this?  Faster of course is better.</p>
  
  <p>Note this is not the same as <a href="https://stackoverflow.com/questions/3793650/convert-boolean-to-int-in-java">Convert boolean to int in Java</a>
  because that question does not consider constant time. </p>