here you go.
static int GetIntegerFromBinaryString(string binary, int bitCount) { if (binary.Length == bitCount && binary[0] == '1') return Convert.ToInt32(binary.PadLeft(32, '1'),2); else return Convert.ToInt32(binary,2); }
Convert it to the 2nd version of the 32-bit number padding, and then just let the Convert.ToInt32 method do the magic.
source share