title: Convert two's complement to sign-magnitude
body: <p>I need to convert from two's complement to sign-magnitude in C using only the operators</p>
  
  <pre><code>! ~ &amp; ^ | + &lt;&lt; &gt;&gt;
  </code></pre>
  
  <p>My approach is to find sign:
  <code>int sign = !(!(a&gt;&gt;31));</code></p>
  
  <p>basically, <code>if sign == 1</code> . I want to flip the number and add 1 else just want to display the number.</p>
  
  <p>The thing is I can't use any loops, if statements etc.
  This is what I'm working on:</p>
  
  <pre><code>int s_M = ((((a+1)&gt;&gt;31)^sign)+1)&amp;sign;
  </code></pre>
  
  <p>any suggestions?</p>