title: Parsing of binary twos-complement number to decimal?
body: <p>Well I'm confused this isn't easier than I thought... I want to convert a twos complement binary string to the appropriate number:</p>
  
  <blockquote>
    <p>-5 = '11111011' according to <a href="https://en.wikipedia.org/wiki/Two%27s_complement#Converting_to_two&#39;s_complement_representation" rel="nofollow noreferrer">Wikipedia</a></p>
  </blockquote>
  
  <p>So I would think the following would return negative 5, but it doesn't. After reading Wikipedia it seems all I have to do is subtract one then invert the bits:</p>
  
  <blockquote>
    <p>~(parseInt('11111011', 2) - 1)</p>
  </blockquote>
  
  <p>But it returns -251. Confusing...</p>
  
  <p>Please note that I will be dealing with many odd bit lengths and all won't be 8 bits.</p>