int i = 20;
string output = Convert.ToString(i, 2); // Base2 formatting
i = -20;
output = Convert.ToString(i, 2);
Value Expected
This is basically the same answer as everyone else has posted, just packaged in a method.
///
/// Method to convert an integer to a string containing the number in binary. A negative
/// number will be formatted as a 32-character binary number in two's compliment.
///
/// self-explanatory
/// if binary number contains fewer characters leading zeros are added
/// string as described above
public static string IntegerToBinaryString(int theNumber, int minimumDigits)
{
return Convert.ToString(theNumber, 2).PadLeft(minimumDigits, '0');
}