11,567 questions
Before you give more details, try an example:
string example = "-1011 1";
int sign = example.StartsWith( "-" ) ? -1 : +1;
int result = sign * Convert.ToInt32( example.TrimStart( '-', '+' ).Replace( " ", "" ), 2 );
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Convert binary string to signed integer like "1111 1111 1" to signed int in case of larger binary length
Before you give more details, try an example:
string example = "-1011 1";
int sign = example.StartsWith( "-" ) ? -1 : +1;
int result = sign * Convert.ToInt32( example.TrimStart( '-', '+' ).Replace( " ", "" ), 2 );