one's complement
<p>I need to find one's complement of a decimal number given as an input. First i Convet the decimal number to a binary number using the following code, </p>

<pre><code>int decNum = int.Parse(Console.ReadLine());
string binRep = " ";
int digi = 0;
do
{
    digi = decNum % 2;
    binRep = digi.ToString() + binRep;
    decNum = decNum / 2;
} while (decNum &gt;= 1);
Console.WriteLine(binRep);
</code></pre>

<p>then when i do this,</p>

<pre><code>int onesComplement= ~(int.parse(binRep)),
</code></pre>

<p>i get weird answers, for example when i give 8 as the input i get 1000 as the binary number but after using the tilde(~) for getting ones complement i get -1001. I would like to know what am i missing here, and what best should i do to get one's complement correctly?</p>
