int i = 20; string output = Convert.ToString(i, 2); // Base2 formatting i = -20; output = Convert.ToString(i, 2);
Value Expected
Negative numbers in .NET are represented in binary as Two's complement.
From MSDN - Convert.ToString Method (Int32, Int32):
If value is negative and toBase is 2, 8, or 16, the returned string uses two's complement representation